Created
September 5, 2013 23:15
-
-
Save aurynn/6457517 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
from twisted.internet import protocol, reactor | |
from twisted.protocols.basic import LineReceiver | |
class myProtocol(LineReceiver): | |
def lineReceived(self, data): | |
# Do some stuff w/ the data | |
p = json.parse(data) | |
self.doStuff(p) | |
def saySomething(self, message): | |
self.sendLine( | |
json.dumps(message) | |
) | |
class myFactory(protocol.Factory): | |
def buildProtocol(self, addr): | |
m = myProtocol() | |
m.factory = self | |
return m | |
# to listen | |
reactor.listenTCP( | |
1234, | |
myFactory(), | |
interface=“localhost” | |
) | |
#to connect | |
reactor.connectTCP( | |
“somewhere.else”, | |
1234, | |
myFactory() | |
) | |
# To start doing stuff | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment