Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. from twisted.protocols import basic
  2. from twisted.internet import protocol, reactor
  3.  
  4. class MuckRoo(basic.LineReceiver):
  5.     delimiter = "\n"
  6.     buffer = []
  7.  
  8.     def connectionMade(self):
  9.         print "Got a connection!"
  10.         self.sendLine("=== Connected to MuckRoo ===")
  11.         if len(self.buffer) > 0:
  12.             self.sendLine("=== Buffer Start ===")
  13.             while len(self.buffer):
  14.                 self.sendLine(self.buffer.pop(0))
  15.             self.sendLine("=== Buffer End ===")
  16.  
  17.     def connectionLost(self, reason):
  18.         print "Lost the connection!"
  19.         self.buffer.append("Some stuff happened after disconnect!")
  20.  
  21.     def lineReceived(self, line):
  22.         print "Received", repr(line)
  23.  
  24. def main():
  25.     factory = protocol.ServerFactory()
  26.     factory.protocol = MyChat
  27.     reactor.listenTCP(5555, factory)
  28.     print "Waiting for connections..."
  29.     reactor.run()
  30.  
  31. if __name__ == "__main__":
  32.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement