Jump to content
  • Advertisement
Sign in to follow this  
supagu

[winsock] read ahead socket + read stream size

This topic is 4708 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

i'm working on some network code, and my server will make 3 send calls to send 3 blocks of data one after the other. The client check to see if the stream is readable, then assumes it has received all 3 blocks of data. As you can imagine, it may have only received the first block of data then i attempt to read in the other 2 blocks i get invalid data back. So my idea around the problem, is to see if i can read in the first block of data (leaving it in the stream so it can be read later) this first block of data has a size of the other 2 blocks of data in it, so then i can check to see if the read buffer is bigger than the 3 buffers so i know all data has been received. so im wondering how to do a read from the stream that doesnt remove the data, and also how to get the size of the read buffer. can i do this? what API methods should i look in to for these operations?

Share this post


Link to post
Share on other sites
Advertisement
You can use a MSG_PEEK flag when recv'ing. This will not actually take the data out of the socket's buffer.

On the other hand, if you put the size of the packet at the beginning of each packet, then you could read everything in the buffer and then process each complete message. The size of the buffer is what is returned from recv()

Share this post


Link to post
Share on other sites
yeah i had a look in to it, apparently its bad to peek in to the buffer, so i've just made a buffer for my socket connections which i can do what i want with :)

Share this post


Link to post
Share on other sites
We've discussed this question to great extent in the networking & multiplayer forum. Take a look at the last week's threads there. Also, the FAQ for that forum has an outline of the solution.

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!