pygame and socket.recv

Tim Wintle tim.wintle at teamrubber.com
Thu Apr 2 03:28:19 CEST 2009


On Wed, 2009-04-01 at 17:58 -0700, Aaron Brady wrote:
> I tried writing a small game on a pygame layer.  The graphics are
> fine, and at the moment, it is not graphics intensive.  It is multi-
> player, and for the communication, I am sending a pickle string across
> a LAN, once per frame.
> 
> I'm observing some latency.  It seems that socket.recv isn't
> performing consistently.

Not sure I understand the question, are you blocking for the data to
come down the network before rendering the next frame?

For game programming I've always used select with non-blocking sockets
to receive data - and kept the transmissions to UDP to save time
(obviously you have to expect some data to be lost). Wire time is always
going to have too much latency for a message to be happily passed within
the time it takes to render a frame.

For syncing time I use a really simple algorithm - both machines send
each other their local [game] time every few seconds, and if the
received time is ahead of the local time then the receiving machine
updates it's time to match - that way they are always out by at most the
shortest time it takes for a packet to travel from one to the other.


Tim Wintle





More information about the Python-list mailing list