BaseServer and BaseConnectionHandler classes

15 views
Skip to first unread message

Jared Kuolt

unread,
Sep 15, 2009, 9:03:11 PM9/15/09
to Tornado Web Server
Tornado has a great, simple interface to epoll, and to capitalize on
that for other servers (not just HTTP), I'd like to see an abstracted
interface to reduce boilerplate. I quickly created BaseServer and
BaseConnectionHandler classes[1] that showcase how they might be
abstracted. It's possible to use these classes under the httpserver
classes. This is a proof-of-concept, most of the code ripped from
httpserver; I'm hoping to get some feedback.

Here's an example script of an Echo server using these classes, which
is considerably smaller than the original implementation I wrote [2]:

from tornado.baseserver import BaseServer, BaseConnectionHandler
from tornado import ioloop

class EchoConnectionHandler(BaseConnectionHandler):
def __init__(self, stream, address, server):
super(EchoConnectionHandler, self).__init__(stream,
address, server)
self.read()

def read(self):
self.stream.read_until("\r\n", self.eof_callback)

def eof_callback(self, data):
self.stream.write(data)
self.read()

server = BaseServer(EchoConnectionHandler)
server.listen(8000)
ioloop.IOLoop.instance().start()


[1]: http://github.com/JaredKuolt/tornado/blob/master/tornado/baseserver.py
[2]: http://superjared.com/entry/building-echo-server-using-tornado/

Bret Taylor

unread,
Sep 15, 2009, 11:50:11 PM9/15/09
to python-...@googlegroups.com
It is a good idea, but one concern I have is that I think the focus of Tornado should be on serving web sites, not necessarily arbitrary servers. Perhaps we can introduce classes like this for power developers, but I hope that Tornado evolves more along the lines of Django in terms of focus (web development) than Twisted (networking).

Let me discuss with other Tornado folks and get back to you.

Bret

Shelby Ramsey

unread,
Sep 16, 2009, 1:20:27 AM9/16/09
to python-...@googlegroups.com
Bret,

I do like focus ... that makes it much easier for noobs to grok.  And I don't think having other base servers will prevent people from creating other protocols besides http.  I've been developing pure networking apps that don't even use tcp using the ioloop core and it's been a breeze.  I see a lot of projects spending a lot of time on "edge cases" and I'd rather see the smart people working on the core .... and of course people can always build these edge cases and publish them for the community if they so choose. 

Just my $0.002 (not that it's worth much).

SDR

Ben Eliott

unread,
Sep 19, 2009, 1:57:52 PM9/19/09
to python-...@googlegroups.com
Hi,

what was the general answer to the tornado team discussion mentioned below?

it would be nice to get an feeling on general direction from the Tornado team. On the one hand there are pro-framework comments like below, and on the other hand plenty of posts saying 'use module x for this and y for that, it not a job for tornado'. 
Reply all
Reply to author
Forward
0 new messages