Jump to content

  • Log In with Google      Sign In   
  • Create Account

Winsock Questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Johannes1991   Members   -  Reputation: 433

Like
0Likes
Like

Posted 22 September 2011 - 06:11 AM

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?
EnJOJ Gaming

Sponsor:

#2 rip-off   Moderators   -  Reputation: 8222

Like
0Likes
Like

Posted 22 September 2011 - 08:21 AM

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?

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?

#3 Johannes1991   Members   -  Reputation: 433

Like
0Likes
Like

Posted 22 September 2011 - 08:39 AM

I'm using WSAAsyncSelect with TCP.

Then thing about 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.
EnJOJ Gaming

#4 ApochPiQ   Moderators   -  Reputation: 15720

Like
0Likes
Like

Posted 22 September 2011 - 11:17 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!

#5 Johannes1991   Members   -  Reputation: 433

Like
0Likes
Like

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!


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

#6 ApochPiQ   Moderators   -  Reputation: 15720

Like
0Likes
Like

Posted 22 September 2011 - 01:04 PM

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

#7 hplus0603   Moderators   -  Reputation: 5304

Like
0Likes
Like

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().
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS