views:

26

answers:

1

I'm using twisted to implement a client and a server. I've set up RPC between the client and the server. So on the client I do protocol.REQUEST_UPDATE_STATS(stats), which translates into sending a message with transport.write on the client transport that is some encoded version of ["update_stats", stats]. When the server receives this message, the dataReceived function on the server protocol is called, it decodes it, and calls a function based on the message, like CMD_UPDATE_STATS(stats) in this case.

If, on the client, I do something like:

protocol.REQUEST_UPDATE_STATS("stats1")
protocol.REQUEST_UPDATE_STATS("stats2")

...am I guaranteed that the "stats1" message arrives before the "stats2" message on the server?

UPDATE: Edited for more clarity. But now the answer seems obvious - no way.

+1  A: 

They will arrive in the order that the request is received by the Python process. This includes the connection setup time plus the packets containing the request data. So no, this is not guaranteed to be the order that the sending processes sent the request, because of network latency, dropped packets, sender-side packet queuing, etc. "In-order" is also loosely defined for distributed systems.

But yes, in general you can count on them being delivered in-order as long as they're separated by a relatively large amount of time (100's of ms over the internet).

Michael Melanson
You can count on them being *sent* in order. Maybe. Depending on what kind of transport you're using, etc. As the zen of Python says: "In the face of ambiguity, refuse the temptation to guess.". This question is highly ambiguous and you really shouldn't answer it until the asker provides more information :).
Glyph