Skip to content

Instantly share code, notes, and snippets.

@aurynn
Created September 5, 2013 23:15
Show Gist options
  • Save aurynn/6457517 to your computer and use it in GitHub Desktop.
Save aurynn/6457517 to your computer and use it in GitHub Desktop.
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