Jump to content
  • Advertisement
Sign in to follow this  
Johannes1991

Winsock Questions

This topic is 2641 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've been playing around with Winsock(non blocking) and there are some things that i don't just get

1: I only get a FD_READ message when i've called the function recv() and a package arrive later. Is it suppose to be like that?
for example if i call recv() 500 times and 100 packages was recieved. Will it keep checking for those 400 other package till the end of the program?

2: When i send a package that is 16 bytes and the recv() size is 256 then the reading of the package isn't always precise and vice versa. Only if the sizes are equal. So should i have a constant size for all of the packages(even if they are less)?.
for example the constant size is 256 but i still send stuff that is 128 bytes, but the first bytes identifies the package so it's used correctly

3: If i should have a constant size then what is the reasonable size?

Share this post


Link to post
Share on other sites
Advertisement
Are you talking about TCP or UDP?

In TCP, there are no "packages". TCP is a stream of bytes. There is no requirement that any given read() call will return the same number of bytes that was given to any particular write() call.

Your application can create "messages" on top of this stream by knowing how to divide the bytes into logical chunks. A common solution is to prefix every logical message with the number of bytes in the message. Others solutions include writing some kind of message type identifier first, and the number of bytes in the message can be inferred from this value.

You don't need to use a fixed message size.


I've been playing around with Winsock(non blocking)... I only get a FD_READ message when i've called the function recv() and a package arrive later. Is it suppose to be like that?
[/quote]
I don't understand this question. Are you setting your sockets into non-blocking mode, or are you using select() to avoid blocking? Can you give an example?

Share this post


Link to post
Share on other sites
I'm using WSAAsyncSelect with TCP.

Then thing about [color=#1C2837][size=2] FD_READ is that i only get it if recv() have been called.

i don't get FD_READ when I KNOW data has been sent to the server.

Share this post


Link to post
Share on other sites
WSAAsyncSelect is evil. I believe the Forum FAQ has a lot of explanations of precisely why. I think you'll have a much easier time of things if you use a different technique for handling your sockets!

Share this post


Link to post
Share on other sites

WSAAsyncSelect is evil. I believe the Forum FAQ has a lot of explanations of precisely why. I think you'll have a much easier time of things if you use a different technique for handling your sockets!


haha ok :)
I'm making a small RTS game so what type of socket would you recommend?

Share this post


Link to post
Share on other sites
Using the standard BSD-style select() is probably the simplest approach for now, and plenty flexible/fast/etc.

Share this post


Link to post
Share on other sites

Using the standard BSD-style select() is probably the simplest approach for now, and plenty flexible/fast/etc.


If you use a single windows message loop and no threads, you should probably combine MsgWaitForMultipleObjectsEx() with select() and a timer to handle all the things you need:

1) User input (windows messages)
2) Game simulation and rendering (timer)
3) Networking (select)

Specifically, pass the socket (which is a real handle on any modern Windows) as an object to wait on in MsgWaitForMultipleObjectsEx().

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!