Skip to content

@schlamar /gevent_sendall.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import sys
import gevent
from gevent.server import StreamServer
from gevent.socket import create_connection
def handle_tcp(socket, address):
print 'new connection'
length = 100
data1 = '1' * 1024 * 1024 * length
data2 = '2' * 1024 * 1024 * length
g1 = gevent.spawn(socket.sendall, data1)
g2 = gevent.spawn(socket.sendall, data2)
gevent.joinall([g1, g2])
print 'data sent'
def client_connect(address):
socket = create_connection(address)
while True:
data = socket.recv(1024 * 1024)
if not data:
print
print 'Data received'
break
else:
sys.stdout.write(data[0])
tcp_server = StreamServer(('127.0.0.1', 1234), handle_tcp)
gevent.spawn(client_connect, ('127.0.0.1', 1234))
tcp_server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.