[SDL] Network thread?

Bob Pendleton bob at pendleton.com
Wed Jan 15 08:27:01 PST 2003


On Wed, 2003-01-15 at 07:13, H. C. wrote:
> Hi all!
> 
> In which way would a multiplayer game profit from an own network traffic
> handling thread instead of putting the handling in the main thread?

Reduced latency is a big one, the network thread can process network
traffic while the main thread is waiting for events and while it is
waiting for the video card to render your graphics. The normal SDL event
processing code only really wakes up every 10 milliseconds (if you wait
for events). So, the network code can be running while the main loop is
blocked.

Simplicity is another advantage. You don't wind up with network code
stuck in the middle of your main loop. Instead you can use internal
queues or even SDL events to communicate with the network code. Clean
code is bugless code.

You might get better performance. Your network code can be written to
wait for network activity instead of having to poll for network
activity. By waiting for network events you don't waste CPU time polling
for activity that hasn't happened. Also, since you read from a socket
ASAP using a thread you reduce the chance that the socket will block and
cause a slow down to ripple back across a TCP/IP connection, or lose
UDP/IP packets because you aren't reading them fast enough.

For more information and code that you can just use take a look at:
http://gameprogrammer.com/game.html

		Bob Pendleton

> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
-- 
+------------------------------------+
+ Bob Pendleton, consultant for hire +
+ Resume: http://www.jump.net/~bobp  +
+ Email:  bob at pendleton.com          +
+------------------------------------+





More information about the SDL mailing list