Skip to content

Instantly share code, notes, and snippets.

@Alligator
Created December 21, 2013 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alligator/8065965 to your computer and use it in GitHub Desktop.
Save Alligator/8065965 to your computer and use it in GitHub Desktop.
import socket
sock = socket.socket(socket.AF_INET, socket.TCP_NODELAY)
sock.connect(('irc.synirc.net', 6667))
sock.setblocking(0)
def irc_connect():
buff = ''
while 1:
try:
data = sock.recv(4096)
buff += data
while '\r\n' in buff:
d, buff = buff.split('\r\n', 1)
yield d
except Exception, e:
yield None
def irc_send():
data = ''
while 1:
msg = yield
data += '\r\n' + msg
sock.sendall(data + '\r\n')
print '>>>', data
in_gen = irc_connect()
out_gen = irc_send()
out_gen.next()
inp = [
'USER comero 8 * comero :hello',
'NICK :comero',
]
while 1:
g = in_gen.next()
if g:
print g
if len(inp) > 0:
out_gen.send(inp.pop())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment