Archived

This topic is now archived and is closed to further replies.

Asynchronous Winsock Client/Server Question

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

As every experience programmer loves to claim, "You can''t count on receiving all your packets all at the same time." So right now I have a non-blocking, multi-client server, and a client to match. When I send data, I send a custom structure first, which tells the type of data that follows, ranging from Ship_position to ship_speed, etc, and the ship ID to which it pertains. Right now, my receive function loops until it receives 8 bytes, the size of the structure, and the same looping method is used for recieving the actual content (sent right after the custom structure) such as position or speed. The time it takes to receive the data in that looping method takes a long time So my game is going fine, freeze for 100 ms, fine, freeze for 100 ms, etc, whenever data is sent to the client. How is stuff like this normally handled in games? Do I call recv once every game loop and then process the buffer for commands, or something??? Thanks for your time! return Neff;

Share this post


Link to post
Share on other sites
What non-blocking I/O model do you implement? For example, if you call WSARecv after an event triggers the socket informing you of incoming data, then you basically have to implement a seperate worker thread for each socket. What if multiple sockets events triggers at simultaneously?

I recommend IOCP. With IOCP, you will read data as it comes. Compare the data you read thus far with the size of the data to ensure you have all the data. Afterward, process the data. In other words, you will have one or two worker threads monitoring IOCP.

Kuphryn

Share this post


Link to post
Share on other sites