Hello, I'm having a problem receiving information with Winsock. I have 2 programs written, one is a server capable of accepting sockets from multiple users, and the other is a simple one socket client.
The server uses an array of a user defined data type with a boolean variable and a socket variable in it, to handle all the clients. It updates at run-time for each user connecting.
After a successful connection is made, both the client and server are put into non-blocking mode using ioctlsocket().
Client send code:
string strSend = "all this packet information!!";
int sz = strSend.size();
send(m_socket, strSend.c_str(), sz, 0);
Server receive code:
// check incoming packets
for (int c=0; c<nSize; c++) {
char recvbuff[1024];
int bytesRecv = 0;
// each socket
bytesRecv = recv(nClients[c].m_socket, recvbuff, 1024, 0);
if (bytesRecv>0) {
string strRecv = recvbuff;
string output = strRecv.substr(0, bytesRecv);
cout << output << endl;
}
}
return;
}
My receiving packet is set at 1024 bytes, but whenever I receive a packet over 10 characters long, my packets tend to stack up. As you see, I cout << output << endl; so that each incoming packet is on its own line. My result is this:
1234567890
1234567890
1234567890
12345678901234567890
12345678901234567890
1234567890
1234567890
12345678901234567890
1234567890
1234567890
1234567890
12345678901234567890
If my packet is say, around 6 characters, I don't ever see this kind of stacking. The larger the packet, the more often they stack. In this case, I use "all this packet information!!", the result is:
all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!all this packet information!!
A stream until it hits 1024 bytes, then it repeats. Help!