I have a question regarding WinSock library. I'm trying to write simple instant messages program. I wrote it only for 2 clients, and now i would like to improve it, so It can work for many of them, and each client would sent an message with its number and number of the client which will recieve message to the server.
Ive got a problem and I can't figue out, why such simple thing doesnt work:
Code of the client function that sends the messages:
void cClientIO::GetID(SOCKET & socket)
{
u_long iMode = 0;
ioctlsocket(socket, FIONBIO, &iMode);
cout << "Type your ID:" << endl;
cin >> buffer;
send(socket, buffer, sizeof(buffer), 0);
cout << "Type reciever ID" << endl;
cin >> buffer;
//We send buffer to the server;
send(socket,buffer,sizeof(buffer), 0);
}
//Here is the server side:
void cRunServer::GetClientInfo(SOCKET & s){
char buffer[256];
int iResult;
//BLOKUJ pls
u_long iMode = 0;
iResult = ioctlsocket(s, FIONBIO, &iMode);
recv(s, buffer, sizeof(buffer), 0);
cout << "Client number: " << buffer << WSAGetLastError() << endl;
iResult = ioctlsocket(s, FIONBIO, &iMode);
recv(s, buffer, sizeof(buffer), 0);
cout << "Attempts to connect to client ID: " << WSAGetLastError() << endl;
}
I dont know what is going on... The first recv block my code, but the second one doesnt, and just goes on... I tried to use GetWSALastError() but it gives me 0 all the time...
Thanks for help in advance.
It doesn't work because the size of the buffers does not match. Client is sending char[2048] and I recv only char[256] and the second call gets the rest of the buffer, and thats why it continues to flow.