Here's some pretty low level networking code I knocked up to encapsulate the actual sending and recieving. It runs in the main thread along with everything else so should be useful for anywhere without them or whatever. I hope somebody else might find it useful considering the amount of talk on here about networking. Oh yeah it's public domain I suppose, don't want anybody stopping others using it or something :p
<br><br>def recv_data(sock):<br> print "receiving"<br> sock.setblocking(0)<br> poller = select.poll()<br> poller.register(sock, select.POLLIN)<br> while True:<br> if poller.poll(0):<br> return
sock.recv(1024)<br> stackless.schedule()<br><br>def send_data(sock, data):<br> sock.setblocking(0)<br> poller = select.poll()<br> poller.register(sock, select.POLLOUT)<br> while True:<br> if poller.poll
(0):<br> sent = sock.send(data)<br> if sent == len(data):<br> break<br> else:<br> data = data[sent:]<br> stackless.schedule()<br><br>Adam.<br>