File Server Help

This is a discussion on File Server Help within the C Programming forums, part of the General Programming Boards category; >Yes, shure but that mistakes are warnings, They are warnings because often times, they are because of bugs in your ...

  1. #76
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >Yes, shure but that mistakes are warnings,

    They are warnings because often times, they are because of bugs in your program. In this case, they are from bugs in your program.

    >fd_set is saying that was no declared, but it's a struct from the sockets library.

    yes, but that's the library. You also need to include the proper header files.

    >The same with the other socket functions..The errors on the recv and the send functions are just warning

    Yes, but in this case, they are signs of bugs in your program.

    >the code compiles perfectly in a simple compilation with gcc,

    Just because it compiles, doesn't mean there aren't bugs in it.

    >what about the select? compile the code in the normal way and check it

    You have other, more basic, errors that are making your program not work right now.

  2. #77
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    So i correct it like this?
    Code:
      recv(*sock, &lastpartsize, sizeof(lastpartsize), 0);
    In case the recv is a char array, I won't need any changes right?
    Does the send function also requires that?
    How can O insert the propper headers?
    Last edited by lautarox; 09-13-2008 at 02:47 PM.

  3. #78
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Yes. If it is an array, the array name degrades to a pointer to its first element, so it would be fine. Yes.

    Comment out the unused variables and fix the other warnings.
    Last edited by robwhit; 09-13-2008 at 02:54 PM.

  4. #79
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    According to the man pages, select (and fd_set etc.) are in <sys/select.h>.

  5. #80
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    You have to reconstruct the fd_sets you pass to select for every call. select removes the file descriptors from the fd_sets that don't have activity on them.

  6. #81
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    I've corrected all the mistakes I had in the recv, send functions and in some vars and comparations.

    But why does it removes the file descriptor from the fd_sets? the sentence is suppose to delete the connection in case that it's not responding, I've tested it as it was originally and it worked perfectly.
    Code:
       if((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) { /* this thing is what I'm worried of*/
            if(nbytes == 0) {
              close(i);
              FD_CLR(i, &master);
              printf("Conexion perdida\n");
            }
            else {
              recievefile(&i);
            }
    I also wanna know what do you think about using fork for handling the requests, I think that the select won't handle the incomming connection if it is doing the function of recieve file, I mean, two people sending a file at the same time is not possible as the code is right now right?
    Last edited by lautarox; 09-13-2008 at 08:37 PM.

  7. #82
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >But why does it removes the file descriptor from the fd_sets?

    the point of select is to tell you which fds wouldn't block if you used some function on them. Removing the inactive fds leaves the active fds, which you can then read/write/send/recv on.

    >the sentence is suppose to delete the connection in case that it's not responding, I've tested it as it was originally and it worked perfectly.

    which line?
    Code:
       if((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) { /* this thing is what I'm worried of*/
            if(nbytes == 0) {
              close(i);
              FD_CLR(i, &master);
              printf("Conexion perdida\n");
            }
            else {
              recievefile(&i);
            }
    I don't know what you're trying to do there.

    >I also wanna know what do you think about using fork for handling the requests,

    do you have a specific question?

    > I think that the select won't handle the incomming connection if it is doing the function of recieve file, I mean, two people sending a file at the same time is not possible as the code is right now right?

    If you want multiple connections with select, you'll have to rearrage your code a little bit, yes. Something like this:
    Code:
    while do socket stuff
        set up fd_sets
        call select
        for each fd in fd_set
            if listener
                accept connection
            else if file receive connection
                recv chunk //only receive a chunk of the file at a time.
            endif
        endfor
    endwhile

  8. #83
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    This line deletes non responding descriptors... It works, as it was originally, a chat server, worked perfectly
    Code:
       if((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) { /* this thing is what I'm worried of*/
            if(nbytes == 0) {
              close(i);
              FD_CLR(i, &master);
    How are you planning to recieve the chunk of the file and add it? Mmm.. maybe doing simplier funcion that just appended all the code recieved... well.. I think maybe that will be a little messed up.
    About fork, I thought of forking the recievefile function on the incoming existent connection.

  9. #84
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Ok, but if there is an error, then it tries to receive the file. Does that sound right?

    >About fork, I thought of forking the recievefile function on the incoming existent connection.

    That's another way of doing it. In that case, you wouldn't need select.

  10. #85
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Ok, but if there is an error, then it tries to receive the file. Does that sound right?
    Mmm.. if nbytes is equal or less than 0 it compares if it is 0, if it is, it closes the socket, maybe I had to add there an else..
    Code:
            if(nbytes == 0) {
              close(i);
              FD_CLR(i, &master);
            else {
              printf("Error ocurred");
              // do something
            }
    Is that what you mean?
    And about for, I think it would be nicer to have the fork and the select working together if the file server has lots of multiple connections.. and also multiple file uploads from the same client
    Last edited by lautarox; 09-14-2008 at 12:38 PM.

  11. #86
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >Is that what you mean?

    Yes. Then you would have to code the condition for when it actually received data.

    >And about for, I think it would be nicer to have the fork and the select working together if the file server has lots of multiple connections.. and also multiple file uploads from the same client

    Why would you want both? It's either one or the other when you're using it for multiple connections.

  12. #87
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Well.. now the recieve function works, but for a strange reason, I don't know why I have to send everything twice from the client

  13. #88
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    ...post your code

  14. #89
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Server File
    http://pastebin.com/m7568fec0
    File Client
    http://pastebin.com/m30cbd08a

    Note that in the file client I've for each send a copy of it, cause if not it doesn't work and I've written lots of printf all over the code to see whats happening on the execution..

  15. #90
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    You're so not paying attention to what I'm telling you.

    Seriously, if you're not going to pay attention to what I'm saying, I think I'll do likewise.

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