Date

I've just released Corotwine, a set of Coroutine APIs for Twisted. You can download Corotwine-0.1.tar.gz. There is very thorough API documentation.

Here's a complete example chat server. Start it up and telnet to port 1025 a couple of times and you'll be able to chat.


from twisted.internet import reactor
from twisted.internet.error import ConnectionClosed
from corotwine.protocol import gListenTCP, LineBuffer


class Chat(object):
def __init__(self):
self.clients = []

def handleConnection(self, transport):
transport = LineBuffer(transport)
self.clients.append(transport)
try:
try:
for line in transport:
for client in self.clients:
if client is not transport:
client.writeLine(line)
finally:
self.clients.remove(transport)
except ConnectionClosed:
return

from twisted.python.log import startLogging
import sys
startLogging(sys.stdout)

gListenTCP(1025, Chat().handleConnection)

reactor.run()

There are more examples in the corotwine/examples.py file.