Last active
December 25, 2015 00:59
-
-
Save aurynn/6891958 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 | |
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