Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.protocols import basic
- from twisted.internet import protocol, reactor
- class MuckRoo(basic.LineReceiver):
- delimiter = "\n"
- buffer = []
- def connectionMade(self):
- print "Got a connection!"
- self.sendLine("=== Connected to MuckRoo ===")
- if len(self.buffer) > 0:
- self.sendLine("=== Buffer Start ===")
- while len(self.buffer):
- self.sendLine(self.buffer.pop(0))
- self.sendLine("=== Buffer End ===")
- def connectionLost(self, reason):
- print "Lost the connection!"
- self.buffer.append("Some stuff happened after disconnect!")
- def lineReceived(self, line):
- print "Received", repr(line)
- def main():
- factory = protocol.ServerFactory()
- factory.protocol = MyChat
- reactor.listenTCP(5555, factory)
- print "Waiting for connections..."
- reactor.run()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement