I am writing a TCP chat program that uses clients and a server. I have got the server, however I am having a bit of trouble with the client. I am trying to use the select() function to check if any data is waiting to be recv'd from the server, but I get an error. My code is C, but I thought I'd still ask here despite this being a C++ forum. Here is a basic outline of my code:
1 2 3 4 5 6 7 8 9 10
/* variable declarations and basic setting up */
FD_ZERO(&read_set);
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
FD_SET(ConnectSocket, &read_set);
select(0, &read_set, NULL, NULL, &timeout); // this always causes an error at runtime
I've missed out various bits and all the error checking for the sake of clarity.
I can send and recv using ConnectSocket, but when I provide read_set as an argument to select() I get error code 10022.
Although, on my server I have used 0 as my first argument to all my calls to select() and it works every time, and according to MSDN ( http://msdn.microsoft.com/en-us/library/ms740141(VS.85).aspx ) the first argument is ignored. Any idea why this is?