Skip to content

Instantly share code, notes, and snippets.

View aurynn's full-sized avatar

Aurynn Shaw aurynn

View GitHub Profile
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(
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!")
from twisted.internet import stdio, protocol, reactor
from twisted.protocols.basic import LineReceiver
import json
class myProtocol(LineReceiver):
def connectionMade(self):
# self.sendLine(json.dumps({"name": "aurynn", "message":"hello"}))
self.io.getNetwork(self)
def lineReceived(self, data):
# Do some stuff w/ the data

Keybase proof

I hereby claim:

  • I am aurynn on github.
  • I am aurynn (https://keybase.io/aurynn) on keybase.
  • I have a public key whose fingerprint is 18D4 255F 6986 1166 676D AD20 0B49 20FA 2CD9 A14E

To claim this, I am signing this object:

@aurynn
aurynn / gist:10023104
Created April 7, 2014 15:59
Simple JSON client 1
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
import json
your_name = "aurynn"
class JsonProtocol(LineReceiver):
def lineReceived(self, msg):
try:
@aurynn
aurynn / gist:10023139
Last active November 2, 2017 17:51
Simple JSON client 2
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet import reactor
from twisted.protocols.basic import LineReceiver
import json
your_name = "aurynn"
class JsonProtocol(LineReceiver):
@aurynn
aurynn / gist:10023253
Last active August 29, 2015 13:58
Simple JSON client 3
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet import reactor
from twisted.protocols.basic import LineReceiver
import json
your_name = "aurynn"
class JsonProtocol(LineReceiver):
@aurynn
aurynn / gist:10023699
Last active August 29, 2015 13:58
Simple JSON Server 1
from twisted.internet import protocol, reactor
from twisted.protocols.basic import LineReceiver
from twisted.internet.endpoints import TCP4ServerEndpoint
import json
class JsonEchoServer(LineReceiver):
"""
@aurynn
aurynn / gist:10074760
Created April 7, 2014 23:52
Echo client lineReceived()
def lineReceived(self, msg):
try:
msg = json.loads(msg)
except json.JSONDecoderError:
print "Received a non-JSON message: %s" % msg
if "message" in msg:
print "<{from}> {message}".format(**msg)
@aurynn
aurynn / gist:10081067
Created April 8, 2014 01:33
stdio protocol
class StdioProtocol(LineReceiver):
from os import linesep as delimiter
def connectionMade(self):
self.connected = True
def __init__(self, wire):
self.chat = wire
wire.output = self