File Server Help

This is a discussion on File Server Help within the C Programming forums, part of the General Programming Boards category; Well.. what do I have to look in the synaptic? How will that help me on my project?...

  1. #31
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Well.. what do I have to look in the synaptic? How will that help me on my project?

  2. #32
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    What do I have to read here?
    If no messages are available at the socket, the receive calls wait for
    a message to arrive, unless the socket is non-blocking (see fcntl(2)),
    in which case the value -1 is returned and the external variable errno
    set to EAGAIN. The receive calls normally return any data available,
    up to the requested amount, rather than waiting for receipt of the full
    amount requested.
    Thats what my program is doing, but that's not my problem, my problem is that it's not asking me for a filename, it just disconnects and exits

  3. #33
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    if(fwrite(buff, 1048576, 1, file) == -1) {
    	printf("Error writing file %s in part: %i", filepath, &i); //prototipo
    }
    else {
    	printf("Part %i Compleated", &i);
    }
    You don't want & there.

  4. #34
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    fwrite returns size_t value
    hard to beleive it will ever return -1
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #35
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Thanks, errors corrected, but why it is not asking me for the filename? it's like that function isn't being executed

  6. #36
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    You send password as a non-null terminated string, and the server doesn't know where the end is, and therefore, the strcmp might always fail.

    Additionally, the recv call might receive more or less than the length of the password.

  7. #37
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    I thought that the password was being sent as a string, do I have to add an \0 to the end of the string to strcmp them?

  8. #38
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    No, to the string you send. strlen doesn't include the nul character. And you also have to only receive the length of the string plus the nul character so that you don't gobble up any data that you need later in your program.

  9. #39
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    I see.. and what about changing the strlen for size?

  10. #40
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Huh?

  11. #41
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    You'r talking about this right? send(sock, password, strlen(password), 0); and you'r telling me that the \0 char is not beeing send, so I have to change it to send(sock, password, sizeof(password), 0); ? or I could try adding the \0 on recieving..

  12. #42
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What's wrong with strlen(password)+1?

  13. #43
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Mmm.. it's still not working..

    ******@******-desktop:~/Escritorio/codigo c$ ./fileclient
    Socket Creado
    test reusando adress
    Conectando // Connecting
    // Not connected
    ******@******-desktop:~/Escritorio/codigo c$ ./fileserver
    Socket Creado
    Port 3000 bindeado
    Socket Listeneando
    Select starteado
    Nueva conexion.. testeando pass //New connection, testing passwd (?)
    Password correcta //correct passwd
    Select starteado // select started
    Conexion perdida // connection lost
    Last edited by lautarox; 09-11-2008 at 01:30 PM.

  14. #44
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Did you start the server before the client?

  15. #45
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Yes I did, if not it wouldn't be connecting to the server, and the server is responding, the sendfile function is not working, I don't really know why

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 02:54 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21