Jump to content
  • Advertisement
Sign in to follow this  
Daivuk

winsock2 prob, all my messages are not recv

This topic is 5410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I created a little multiplayer game. But when my guy shoot with a machine gun, I send the bullet to the other player (server than players whatever). But not ALL the bullets are recieved :S I did it like that for sending : send(Socket, Buffer, NbByte, 0); and for recieving : int NbByte = recv(Socket, mBuffer, 65000, 0); and for creating the socket : socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); Question 1 : Are the sent messages are sure to be recieved? Question 2 : When calling recv(), if multiple messages arrive in same time, do it will put them in one buffer of they will be accessible the next time I call recv() ? (hey, sorry about my english :P) thanks for help ;)

Share this post


Link to post
Share on other sites
Advertisement
With TCP/IP, all the messages are guaranteed to be received. Unless the connection gets dropped. TCP/IP is a stream based protocol. If a "fired bullet" message is 32 bytes, and you send 10 of them (320 bytes), then you might get 300 bytes in the first recv() call, which isn't even a multiple of a whole message. You need to keep recv()ing data until you have as much as you need (32 bytes in this example), and then process the data, then read the next chunk of data.

Share this post


Link to post
Share on other sites
Ok so all the 10 bullets will be in my Buffer when I recv?
So I have to check my buffer until I didnt read all the messages?
That's exactly what I did :S


int NbByte = recv(Socket, mBuffer, 65000, 0);
int NbByteRead=0;
while (NbByteRead < NbByte)
{
NbByteRead += Network.TraiteReceivedData(&(mBuffer[NbByteRead]));
}





I write the incomming data and when I shot I recieve 30 Bytes. (the size of my shot message).
But when I use the shotgun for example, it shot 10 shots, so 300 Bytes. But I only recv() message with 30byte long. multiple time, but not all the 10.

Quote:

then you might get 300 bytes in the first recv() call


did you mean recv can only get 300 bytes at time!?

[Edited by - Daivuk on September 25, 2004 10:42:16 AM]

Share this post


Link to post
Share on other sites
Ok, I think its my mistake, all my messages are recieved, its when I create my shot in my programe ;)
Thanks for help anyway !

Share this post


Link to post
Share on other sites
What he meant is that by default, for TCP, when sending multiple small packet to the same address in a short time, the network layer will try to package the packets together to send 1 big packet instead of many small one.

Because of this, you can also receive packet fragment and thus need to read all the fragment to be sure you have everything. (assuming you're using Winsock, just check if recv() return 0 and call WSAGetLastError and check if you have WSAEMSGSIZE, indicating that data are still in the recv queue ).

Gizz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!