示例#1
0
 def dataReceived(self, data):
     if self.protocol:
         # Pass the data off to the real protocol
         return self.protocol.dataReceived(data)
     
     # Try to determine the protocol requested
     if self.data:
         data = self.data + data
     self.data = data
     self.log.debug("Received %r", data)
     
     if len(data) >= 4:
         if "\0" in data:
             # Binary data; use DCSP
             self.switchProtocol(DaideServerProtocol())
             self.transport.setTcpKeepAlive(True)
         elif data.startswith("DPP/"):
             self.switchProtocol(DppProtocol())
             self.transport.setTcpKeepAlive(True)
         else:
             # Probably text; switch to HTTP
             proto = HTTPChannel()
             
             # Simulate Site.buildProtocol()
             site = self.factory.site
             proto.site = site
             proto.requestFactory = site.requestFactory
             proto.timeOut = site.timeOut
             
             self.switchProtocol(proto)