Skip to content

Instantly share code, notes, and snippets.

@aurynn
Last active December 25, 2015 00:59
Show Gist options
  • Save aurynn/6891958 to your computer and use it in GitHub Desktop.
Save aurynn/6891958 to your computer and use it in GitHub Desktop.
from twisted.internet import protocol, reactor
from twisted.protocols.basic import LineReceiver
import json
class myProtocol(LineReceiver):
def lineReceived(self, data):
# Do some stuff w/ the data
# p = json.loads(data)
self.transport.write("Hi!")
class myFactory(protocol.Factory):
def buildProtocol(self, addr):
m = myProtocol()
m.factory = self
return m
reactor.listenTCP(
1234,
myFactory()
)
reactor.run()
# Links!
servers: https://twistedmatrix.com/documents/current/core/howto/servers.html
clients: https://twistedmatrix.com/documents/current/core/howto/clients.html
doing STDIO: http://stackoverflow.com/questions/8068085/simultaneously-log-and-take-commandline-input-using-twisted
GIST: https://gist.github.com/aurynn/6457517
STDIO example, working: https://gist.github.com/aurynn/6892706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment