Created
January 9, 2016 16:12
-
-
Save sandeep048/cbc1efd46fe7b09f5b7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) Sandeep Pathivada. | |
""" | |
An example unix socket server that sends heartbeat messages. | |
""" | |
from twisted.internet.protocol import Factory | |
from twisted.protocols.basic import LineReceiver | |
from twisted.internet import reactor, protocol | |
from twisted.internet.task import LoopingCall | |
class HeartBeat(LineReceiver): | |
def connectionMade(self): | |
self.loop = LoopingCall(lambda: self.sendLine("2 seconds have passed")) | |
self.loop.start(2, now=True) | |
def lineReceived(self, line): | |
print('Received: ' + line) | |
self.sendLine("Thanks for sending me a message") | |
def main(): | |
factory = protocol.ServerFactory() | |
factory.protocol = HeartBeat | |
reactor.listenUNIX('cfri.sock', factory) | |
reactor.run() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment