[Twisted-Python] order of remote requests

Andrew Bennetts andrew at bemusement.org
Wed Dec 30 00:55:59 EST 2009

Wolfgang Rohdewald wrote:
> I should have given more details, sorry.
> I am writing both the server and the client with twisted pb.
> The server (a game server) sends messages to four player clients.
> Say the game server sends messages A and B to a player client. 
> Is it granted that the player client always processes A first even
> if the internet routes the messages differently and B arrives
> first?

A PB connection uses a single TCP connection.  TCP guarantees that the
bytes will arrive in order (or not at all), so the messages will arrive
at the client in the order the server sent them, assuming there is one
persistent PB connection between each client and the server (which seems
likely from your description).

So it is impossible for the internet to route the messages such that B
will arrive before A.

Neither PB nor TCP guarantee anything about when the recipient
“processes” those messages though, just that they will arrive in the
order they were sent.  For example consider if A and B arrive very close
together (in the same millisecond, say) and the client processes them by
dispatching to a thread pool, which might take 10s or even 100s of
milliseconds to fully process the message (and determine a reply, if
applicable)... then depending on the exact work required and exactly how
the OS schedules the threads, then B might be fully processed before A
is, even though A arrived first.

Apologies for such a pedantically precise and abstract answer, but what
exactly you mean when you say “processes” is a bit ambiguous.  I hope
this reply helps.


More information about the Twisted-Python mailing list