the strings i'm getting back from recv aren't what I thought they would be...
On the client side, I gather input to send over a socket with this simple code:
1 2 3
|
printf("Type your command: ");
scanf("%s", buf);
send(s, buf, strlen(buf), 0);
|
And then on the server side, I want to perform some operations depending on the message. Like if the user types "login hisUsername hisPass" I want to run a function that checks out the username and pass against registered users. So on the server side I recv the messages from the client like so:
[core] int len = recv( s, buf, MAX_LINE, 0 );
buf[len] = 0;
gotmessage(buf,s);[/code]
Easy enough. Gotmessage goes through and parses the incoming string, which correctly identifies 'login', but it also prints out the entire string passed to it in buf. and whenever i type anything with a space, it prints it out as two different lines (meaning recv returned once with the first piece until the whitespace, then again at the next whitespace, etc).
I tried to put MSG_WAITALL in the flags, maybe I didn't do it right, but that made recv return instantly when there wasn't even anything coming in on the socket..
I put a breakpoint on the recv loop on the server, then sent it the message "AAA BBB CCC DDD" from the client. The first time it went through it got only "AAA" as the message. Then it got "BBBCCCDDD" and looks like it ignored whitespace. How do I get it to NOT ignore whitespace? And to wait on the whole thing without spasing out? Is send doing this or is recv?