On Tue, Oct 30, 2012 at 10:04 AM, Phil Mayers <[email protected]>wrote:
> Would it not make more sense to subclass Site and swap out the Channel > implementation for one that can be "pointed" somewhere else? It means > you have to use that "Site" for any WebSocket enabled site, but it would > be clean otherwise. Like so: > Just to be clear (I'm not sure it matters): SockJS is something that gives a WebSockets API on the client side, but implements that using whatever the best API is available there. It may in fact be implemented using a whole host of things, including XHR streaming and polling, iframes, ... > class WebSockCapableChannel(http.HTTPChannel): > def __init__(self): > http.HTTPChannel.__init__(self) > self.websocket = False > > def startWebSocket(self, proto): > self.websocket = True > self.websocket_proto = proto > proto.transport = someWrapper(self) > proto.connectionMade(...) > self.setRawMode() > > def rawDataReceived(self, data): > if self.websocket: > self.websocket_proto.dataReceived(data) > else: > http.HTTPChannel.rawDataReceived(self, data) > > class WebSocketSite(server.Site): > procol = WebSockCapableChannel > > ...then in your "Resource" do: > > class MyResource(...): > def render(...): > request.channel.startWebSocket(someProto()) > I'll try that; but isn't render called when an awful lot of parsing has already been done? Query arguments and headers are already read and parsed; sockjs-twisted expects its first line to be "POST /echo/bla/bla/bla HTTP/1.1\r\n" :) -- cheers lvh
_______________________________________________ Twisted-Python mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
