[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] network



On Mon, 2004-06-28 at 16:17, Pete Shinners wrote:
> I've read code that uses both sockets and twisted, and personally, the 
> vanilla sockets always looks like a win to me. The benefit of twisted is 
> that it supports about every protocol in use. But if you are just going 
> to be passing your own message types over the socket, why bother?

For one thing, Twisted has a protocol called Perspective Broker. It's
basically an RPC mechanism but it integrates beautifully with Python and
shields the user from the low-level details. It probably isn't much good
for high-speed communication but it handles everything else.

Take a look at the echo server and client example
(http://www.twistedmatrix.com/documents/current/examples/pbecho.py and
http://www.twistedmatrix.com/documents/current/examples/pbechoclient.py)
to see what I mean.

> When you say you prefer twisted, how are you using it? Isn't it just 
> some tool for "send a message", "has a message arrived"? How is that 
> better than socket with select? Or if you need, the asyncore module has 
> already tied those together for you.

Another really cool thing is the Deferred object. It is an object that
is returned by functions as a promise that they will eventually give a
result. The caller adds callbacks to it that are notified when the a
result has been generated.

Twisted abstracts socket programming into a clean object-orientated
system. It includes many classes that do things from authentication to
object serialisation that you can extend for your own protocols.

-- 
Timothy Stranex <timothy@stranex.com>

Attachment: signature.asc
Description: This is a digitally signed message part