Members - Reputation: 433
Posted 22 September 2011 - 06:11 AM
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?
Moderators - Reputation: 9250
Posted 22 September 2011 - 08:21 AM
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 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?
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?
Moderators - Reputation: 16720
Posted 22 September 2011 - 11:17 AM
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
Members - Reputation: 433
Posted 22 September 2011 - 11:49 AM
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!
I'm making a small RTS game so what type of socket would you recommend?
Moderators - Reputation: 6018
Posted 22 September 2011 - 04:57 PM
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().