Sign in to follow this  

Preferred method for receiving data

This topic is 3586 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 implemented two types of clients that receive data, was wondering which is the more preferred (best practices) method or if you could share pitfulls or short comings of each: 1. Using WM_SOCKET and WSAAsyncSelect via Windows messaging 2. Using Select() with a timout and constant polling in the main game loop 3. Other? I am programming in VC2008 C++ and am making a strategy multiplayer game... Also, for #2 what is a good time to use for a time out, I was using 0.015S but I just picked that number out of the air such that it wouldn't effect 60fps (1/60=0.017s). I guess it would depend on the game so I'm curious what each of you use for your type of game (assuming this is the method you are using)... Thanks,

Share this post


Link to post
Share on other sites
Quote:
Original post by becoolnike
Lol, it depends on many things: type of game, No of players, type of app ect..

No worry about how the data is recieving worry about the protocol udp or tcp.


I did specify the game type. Max number of players is 8. I'm using tcp since data correctness is more important than speed...

Quote:

Check the Forum FAQ.


I did go through the FAQ, that's how I learned to set up the two systems, but no where did I find reference of which method is preferred or the short comings of each, I found code and examples of each where each author just presented the material... also, no mention of a suggested timeout, one example used 2.5s... I'm new to this so I'd appreciate any advice...

Quote:

Personally, I prefer WSAEventSelect if the code doesn't need to be portable, because it takes the application window (Or a hidden window) out of the system, and allows you to make it threaded easily by doing a blocking wait on WSAWaitForMultipleEvents..

Hmm, interesting, thanks... this is the type of input that is valuable... have you run into any road blocks or problems... what type of game/application are you writing?

[Edited by - rhuala on February 13, 2008 4:17:56 PM]

Share this post


Link to post
Share on other sites
The Forum FAQ says that asynchronous sockets are evil (that's WSAAsyncSelect), and gives some reasons why. It recommends using just select(), unless you need massive scalability, in which case it recommends IOCP with overlapped I/O on sockets for Windows.

Share this post


Link to post
Share on other sites
Personally, I think select() with non-blocking sockets is going to be your best bet. It works great for anywhere from small to large connection numbers depending on how well your netcode is written. Another option would be to have each connection in its own thread using blocking sockets (requires mutex).

On another note, the WSA functions are windows only which means portability goes out the window if you use them.

As for the server update loop, I usually pick 100ms max timeout since that gives 10 updates per second which is usually more than enough (unless it's a FPS). This works well since the user very rarely sends more than 10 updates per second to the server.

Share this post


Link to post
Share on other sites
Quote:
I think select() with non-blocking sockets is going to be your best bet.


You don't need non-blocking sockets when you use select(). If select() returns a socket as readable or writable, then it is guaranteed that the next call to send() or recv() (or sendto()/recvfrom()) will:
1) make some progress
2) not block

Share this post


Link to post
Share on other sites

This topic is 3586 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this