For some reason, recv is returning instantly with -1. The main function of my program spawns a thread for the rec function and then calls the input function directly. The socket that both send and recv are using is a global variable.
Any ideas why recv is returning instantly with -1? The code on the server side is:
1 2 3 4 5
// Send and receive data.
char buf[MAX_LINE];
int len = recv( s, buf, MAX_LINE, 0 );
buf[len] = 0;
send( s, buf, strlen(buf), 0 );
And I know it works just fine. (expected behaviour is that it just sits there waiting for message from client, then obviously echoes it back.)
Are you error checking when you are trying to open the sockets etc? If you get a weird value (most return -1 or similar) you can call WSAGetLastError() to get what specifically went wrong. You can look up the return values at msdn.com, but most of them are self explanatory.
ok well, i'm not sure what's going on now because i'm not getting the same errors. I was getting an error telling me the stack around buf2 was corrupted each time. now it's working as expected. However, recv is returning instantly with 0. it should be blocking waiting for a message from the server but none is being sent so it should block forever... :( i'll have to fiddle some more