On Thu, May 23, 2013 at 9:46 AM, abhishek unnikrishnan < thecreator...@gmail.com> wrote:
> hi guys > Hi Abhishek! > i'm new to twisted and asynchronous programming . i have created a rpc > server using twisted and xmlrpc packages . i wanted to know what will > happen if two or more clients give an rpc call at the same time. how will > the server handle this situation. > The tricky part is in the "at the same time". Twisted's reactor thread only does one thing at a time, and that's okay: both connections get accepted and some data gets read from them (and eventually written to them). The important part is that you do these things non-blockingly (or, synonymously, asynchronously): it's okay to only do one thing at a time as long as each thing you do takes very little time. The second connection doesn't have to wait long before the connection gets opened and data gets read, because the operations that happen before it don't take long. This pattern repeats throughout asynchronous programming: it's okay to only decode one bit of JSON at a time, as long as doing that doesn't take a long time (i.e. block), preventing anything else from happening in the immediate future. Does that clarify things? and also wanted to know is there a way for the server to call the client in > an rpc scenario . > That depends on your RPC protocol. Many allow this (often called peer to peer), many are explicitly client-server and only allow one-way calls. Even protocols that do support full-duplex communication don't necessarily have clients that can take method calls very often. AMP, my personal favorite, explicitly supports two-way RPC. It comes with twisted, and you can read about it here: http://amp-protocol.net/ Alternatively, I think JSON-RPC is full-duplex too. cheers lvh
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python