<div class="gmail_quote">On Tue, Oct 30, 2012 at 10:04 AM, Phil Mayers <span dir="ltr">&lt;<a href="mailto:p.mayers@imperial.ac.uk" target="_blank">p.mayers@imperial.ac.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Would it not make more sense to subclass Site and swap out the Channel<br>
implementation for one that can be &quot;pointed&quot; somewhere else? It means<br>
you have to use that &quot;Site&quot; for any WebSocket enabled site, but it would<br>
be clean otherwise. Like so:<br></blockquote><div><br>Just to be clear (I&#39;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, ...<br>

 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
class WebSockCapableChannel(http.HTTPChannel):<br>
   def __init__(self):<br>
     http.HTTPChannel.__init__(self)<br>
     self.websocket = False<br>
<br>
   def startWebSocket(self, proto):<br>
     self.websocket = True<br>
     self.websocket_proto = proto<br>
     proto.transport = someWrapper(self)<br>
     proto.connectionMade(...)<br>
     self.setRawMode()<br>
<br>
   def rawDataReceived(self, data):<br>
     if self.websocket:<br>
       self.websocket_proto.dataReceived(data)<br>
     else:<br>
       http.HTTPChannel.rawDataReceived(self, data)<br>
<br>
class WebSocketSite(server.Site):<br>
   procol = WebSockCapableChannel<br>
<br>
...then in your &quot;Resource&quot; do:<br>
<br>
class MyResource(...):<br>
   def render(...):<br>
     request.channel.startWebSocket(someProto())<br></blockquote></div><br>I&#39;ll try that; but isn&#39;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 &quot;POST /echo/bla/bla/bla HTTP/1.1\r\n&quot; :)<br>

<br clear="all"><br>-- <br>cheers<div>lvh</div><br>