Advertisement

Asynchronous Winsock Client/Server Question

Started by November 10, 2002 09:21 PM
1 comment, last by Neff 22 years, 2 months ago
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;
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
Advertisement
*boggle* I''ll get back to this in a while, so don''t bother checking back for updates.

return Neff;

This topic is closed to new replies.

Advertisement