File Server Help

This is a discussion on File Server Help within the C Programming forums, part of the General Programming Boards category; > recivi=recv(*sock, buff, sizeof(buff), 0); You only send 4 bytes down the socket. Why are you trying to read 30? ...

  1. #61
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > recivi=recv(*sock, buff, sizeof(buff), 0);

    You only send 4 bytes down the socket. Why are you trying to read 30?
    Code:
    char *passpointer;
    int hasnull;
    int letras;
    passpointer = buff;
    for(i=0;i<strlen(buff)+1;i++) {
    	if(passpointer != '\0') {
    		passpointer++;
    		letras++;
    	}
    	else {
    		hasnull=1;
    	}
    }
    printf("has null?: %i Letras: %i\n", hasnull, letras);
    Replace with:
    Code:
    printf("has null?: yes, eventually Letras: %lu\n", (unsigned long) strlen(buff));

  2. #62
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    I putted 30 in the buffer because I plan to have a dinamic password, but what about the select?

  3. #63
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by lautarox View Post
    Well.. now I'm having a problem with the select, it's like its not recv and sending all the things the function on the select is asking for, it's like if the select were catching all the information sended..
    What do you mean by "catch the information"?
    Quote Originally Posted by lautarox View Post
    Sure, what about using fork() ?
    For multiple connections? That's one way, but select can handle multiple connections too.
    Quote Originally Posted by lautarox View Post
    what about the select?
    Seems fine, AFAICT.
    Code:
    if((newfd = accept(listener, (struct sockaddr *)&clientaddr, &addrlen)) == -1) {
        perror("Server-accept() error lol!");
    }
    Might want to put a break; in there.

  4. #64
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Yeah, seems fine, but it's not executing the function to recieve the file, compile it by you'r own and check that, I've putted a printf in the recievefile function to check if it was being executed and it's not.
    I thought that the select was catching all the sends that the client made but it wasn't doing the function

  5. #65
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > Might want to put a break; in there.

    I meant a continue;.

    I should've said this a while ago but...

    Turn up your compiler warnings. Compile with this:

    gcc -ansi -pedantic -Wall -Werror -Wextra fileclient.c -o fileclient
    Last edited by robwhit; 09-13-2008 at 08:28 AM.

  6. #66
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Mmm.. that only shows error on the comments &#172;&#172;..
    What about the continue thing? where should I put it? and why?
    And.. what about the fread an fwrite, is that ok?
    lol, too many questions, but I want to learn perfectly how the sockets and the file manipulation work =P
    Last edited by lautarox; 09-13-2008 at 09:03 AM.

  7. #67
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Actually if that's the only error you have, then I don't have an up to date copy. Please attach it again.

    Why not just delete those characters?

    And actually, since you're using // style comments and declarations in code, then you should use this:

    gcc -std=c99 -pedantic -Wall -Werror -Wextra fileclient.c -o fileclient

    You should put the continue there so that it doesn't continue processing a socket that is not valid. It will cause the iteration of the loop to be aborted, and it will continue on the next iteration.
    Last edited by robwhit; 09-13-2008 at 11:39 AM.

  8. #68
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Well.. that way of compiling is still not showing anything important, just vars without use and things like that..
    What about the execution of the code inside the select and the fwrite and fread funciton?
    I haven't changed the code

  9. #69
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Well something's not adding up, because if you didn't change the code, then this is what I get:
    Code:
    ~$ gcc -std=c99 -pedantic -Wall -Werror -Wextra fileclient.c -o fileclient
    cc1: warnings being treated as errors
    fileclient.c: In function 'sendfile':
    fileclient.c:53: warning: suggest parentheses around assignment used as truth value
    fileclient.c:58: warning: suggest parentheses around assignment used as truth value
    fileclient.c:60: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:61: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:64: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:69: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:79: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c: In function 'main':
    fileclient.c:129: warning: passing argument 2 of 'recv' makes pointer from integer without a cast
    fileclient.c:131: warning: unused variable 'buf2'
    fileclient.c:100: warning: unused variable 'j'
    fileclient.c:100: warning: unused variable 'i'
    fileclient.c:99: warning: unused variable 'addrlen'
    fileclient.c:97: warning: unused variable 'nbytes'
    fileclient.c:96: warning: unused variable 'buf'
    fileclient.c:93: warning: unused variable 'serveraddr'
    ~$
    The bolded lines are "game over" errors.

  10. #70
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    But it's not wrong, I'm using a pointer to the first socket, and works fine, exept for the function inside the select

  11. #71
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Then you changed your code since you last posted it. Could you attach your current code?

  12. #72
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    It's almost the same, if you can make it work, check the select and the write and read function.
    I'm also interested in game programming, can you recommend me a good library like conio.h for windows, or something better? I want to make an online pong in console =)
    Attached Files Attached Files

  13. #73
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    http://en.wikipedia.org/wiki/Ncurses

    Here are the errors I get:
    Code:
    ~$ gcc -std=c99 -pedantic -Wall -Werror -Wextra fileclient.c -o fileclient
    cc1: warnings being treated as errors
    fileclient.c: In function 'sendfile':
    fileclient.c:53: warning: suggest parentheses around assignment used as truth value
    fileclient.c:58: warning: suggest parentheses around assignment used as truth value
    fileclient.c:60: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:61: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:64: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:69: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c:79: warning: passing argument 2 of 'send' makes pointer from integer without a cast
    fileclient.c: In function 'main':
    fileclient.c:129: warning: passing argument 2 of 'recv' makes pointer from integer without a cast
    fileclient.c:131: warning: unused variable 'buf2'
    fileclient.c:100: warning: unused variable 'j'
    fileclient.c:100: warning: unused variable 'i'
    fileclient.c:99: warning: unused variable 'addrlen'
    fileclient.c:97: warning: unused variable 'nbytes'
    fileclient.c:96: warning: unused variable 'buf'
    fileclient.c:93: warning: unused variable 'serveraddr'
    ~$ gcc -std=c99 -pedantic -Wall -Werror -Wextra fileserver.c -o fileserver   
    cc1: warnings being treated as errors
    fileserver.c: In function 'passwdcheck':
    fileserver.c:39: warning: comparison between signed and unsigned
    fileserver.c: In function 'recievefile':
    fileserver.c:66: error: incompatible types in assignment
    fileserver.c:71: warning: passing argument 2 of 'recv' makes pointer from integer without a cast
    fileserver.c:72: warning: passing argument 2 of 'recv' makes pointer from integer without a cast
    fileserver.c:75: warning: suggest parentheses around assignment used as truth value
    fileserver.c:79: warning: comparison between signed and unsigned
    fileserver.c:83: warning: format '%i' expects type 'int', but argument 2 has type 'char *'
    fileserver.c:88: warning: passing argument 2 of 'recv' makes pointer from integer without a cast
    fileserver.c: In function 'main':
    fileserver.c:102: error: 'fd_set' undeclared (first use in this function)
    fileserver.c:102: error: (Each undeclared identifier is reported only once
    fileserver.c:102: error: for each function it appears in.)
    fileserver.c:102: error: expected ';' before 'master'
    fileserver.c:116: warning: implicit declaration of function 'FD_ZERO'
    fileserver.c:116: error: 'master' undeclared (first use in this function)
    fileserver.c:117: error: 'read_fds' undeclared (first use in this function)
    fileserver.c:147: warning: implicit declaration of function 'FD_SET'
    fileserver.c:155: warning: implicit declaration of function 'select'
    fileserver.c:161: warning: implicit declaration of function 'FD_ISSET'
    fileserver.c:164: warning: pointer targets in passing argument 3 of 'accept' differ in signedness
    fileserver.c:185: warning: implicit declaration of function 'FD_CLR'
    fileserver.c:114: warning: unused variable 'j'
    ~$
    How are you compiling your code?

  14. #74
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Yes, shure but that mistakes are warnings, fd_set is saying that was no declared, but it's a struct from the sockets library. The same with the other socket functions..
    The errors on the recv and the send functions are just warning the code compiles perfectly in a simple compilation with gcc, what about the select? compile the code in the normal way and check it

  15. #75
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Any warning that tells you that you are passing the wrong thing into a function is "not compiling perfectly" but an indication that you are grossly misusing something. The second argument of recv must be a pointer and must not be a straight integer. Until you fix that, your program has no hope of working properly.

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, 07:51 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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