J
Jonathan Hayward
I'm trying to have a client open a socket, send two pickled hashes,
and receive a pickled object (I'm also writing the server, to listen,
read two pickled hashes, and send a pickled object). I've been able to
boil down what doesn't work to a small demo case:
____________________________________________________________
SERVER:
#!/usr/bin/python
import cPickle, socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("", 1234))
sock.listen(5)
try:
newsocket, address = sock.accept()
sockOut = newsocket.makefile("wb")
sockIn = newsocket.makefile("rb")
cPickle.load(sockIn)
cPickle.load(sockIn)
cPickle.dump("Hello, world!", sockOut)
newsocket.close()
sockOut.close()
sockIn.close()
finally:
sock.close()
____________________________________________________________
CLIENT:
#!/usr/bin/python
import cPickle, socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 1234))
sockOut = sock.makefile("wb")
sockIn = sock.makefile("r")
cPickle.dump({}, sockOut)
cPickle.dump({}, sockOut)
response_data = cPickle.load(sockIn)
print response_data
sockOut.close()
sockIn.close()
sock.close()
____________________________________________________________
When I start the server and then start the client, they both hang, as
has happened with the real script. Can you tell me what I am misusing
and preferably how to correct it?
TIA,
++ Jonathan Hayward, (e-mail address removed)
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com
and receive a pickled object (I'm also writing the server, to listen,
read two pickled hashes, and send a pickled object). I've been able to
boil down what doesn't work to a small demo case:
____________________________________________________________
SERVER:
#!/usr/bin/python
import cPickle, socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("", 1234))
sock.listen(5)
try:
newsocket, address = sock.accept()
sockOut = newsocket.makefile("wb")
sockIn = newsocket.makefile("rb")
cPickle.load(sockIn)
cPickle.load(sockIn)
cPickle.dump("Hello, world!", sockOut)
newsocket.close()
sockOut.close()
sockIn.close()
finally:
sock.close()
____________________________________________________________
CLIENT:
#!/usr/bin/python
import cPickle, socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 1234))
sockOut = sock.makefile("wb")
sockIn = sock.makefile("r")
cPickle.dump({}, sockOut)
cPickle.dump({}, sockOut)
response_data = cPickle.load(sockIn)
print response_data
sockOut.close()
sockIn.close()
sock.close()
____________________________________________________________
When I start the server and then start the client, they both hang, as
has happened with the real script. Can you tell me what I am misusing
and preferably how to correct it?
TIA,
++ Jonathan Hayward, (e-mail address removed)
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com