[Twisted-Python] order of remote requests

David Ripton dripton at ripton.net
Tue Dec 29 08:58:04 EST 2009

On 2009.12.29 12:53:07 +0100, Wolfgang Rohdewald wrote:
> On Tuesday 29 December 2009, Andrew Bennetts wrote:
> > Wolfgang Rohdewald wrote:
> > > when I send two remote calls A and B over the network, in that
> > > order, using the twisted perspective broker callRemote method,
> > > is it granted that A is processed first on the other side even
> > > if B  arrives first? Or should I only send B after I got an
> > > answer to A?
> > 
> > It depends on the server, and what exactly you want to happen.
> > 
> > Perspective broker can have many concurrent remote calls on the
> >  same connection, and depending on how the server is implemented it
> >  might process those sequentially in the order they arrive, or
> >  concurrently, or even in an arbitrary order.
> > 
> > So if call A really must be completed before starting B, then the
> >  client must not make call B until it knows A has finished.
> 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?

TCP guarantees in-order message delivery.  If you send A before B over
the same TCP connection, and A and B reach the client, then the client
will receive A before B.

Each Twisted process is single-threaded by default.

So if you use TCP, and keep the message processing code simple, then I
think you'll get messages processed in the order you expect.  I've never
noticed a problem with out-of-order messages in my PB game, anyway.

David Ripton    dripton at ripton.net

More information about the Twisted-Python mailing list