Eventlet client-server
Posted
by johannix
on Stack Overflow
See other posts from Stack Overflow
or by johannix
Published on 2010-05-26T00:02:17Z
Indexed on
2010/05/26
0:11 UTC
Read the original article
Hit count: 633
I'm trying to setup a server-client interraction:
- Server gets a string from client
- Server returns data to client
I got this working with socket.send and socket.recv, but was wondering how to get it working with files through socket.makefile.
I've got most of the pieces working, but don't know how to force each of the pieces to read at the appropriate time. So what it looks like is happening is that both the client and server are reading on the socket at the same time. Any ideas on how to let the server complete the original read before the client starts waiting for its information? Below are the core pieces that reproduce the read lock.
Server:
def handle(green_socket):
file_handler = green_socket.makefile('rw')
print 'before server read'
lines = file_handler.readlines()
print "readlines: %s" % (lines)
print '** Server started **'
server = eventlet.listen((HOST, PORT))
pool = eventlet.GreenPool()
while True:
new_sock, address = server.accept()
pool.spawn_n(handle, new_sock)
Client:
from eventlet.green import socket
green_socket = eventlet.connect((HOST, PORT))
file_handler = green_socket.makefile('rw')
print 'before write'
file_handler.writelines('client message')
file_handler.flush()
print 'before client read'
lines = file_handler.readlines()
© Stack Overflow or respective owner