[zeromq-dev] Noob question - pyzmq & ZMQ_STREAM sockets
Virgil Palanciuc
virgilp at adobe.com
Thu Feb 20 10:58:21 CET 2014
Well… I did have some problem with “no response is sent back” but I can’t
reproduce it now, it was probably user error.
But I’m still confused about the “Exception ignored” message that I get
when the server closes the HTTP connection.
Here’s the updated program (doesn’t use send_multipart) - it still gives
me "Exception zmq.error.ZMQError: ZMQError('Bad address') in
<zmq.backend.cython.message.Frame object at 0x1093fe5f0> ignored”
Some other experiments I did:
- If I remove the “copy=False” arguments, everything still works but I
"ERROR: unexpected exception Bad address” (similar, but not exactly
identical!). I had expected this to be somehow related to the “clientid”,
but no, apparently it only matters if I set “copy=False” in the last
packet (the null one that terminates the connection -ie. socket.send(b'',
flags=zmq.SNDMORE, copy=False) )
- If I just close the connection immediately after receiving the message
(i.e. I don’t send the HTTP response, I just send the clientid + null
message), I get the exact same errors.
Virgil.
===========
import zmq
context = zmq.Context()
socket = context.socket(zmq.STREAM)
socket.bind("tcp://*:5555")
while True:
try:
# Wait for next request from client
clientid, message = socket.recv_multipart();
print("id: %r" % clientid)
print("request:",message.decode('utf8'))
socket.send(clientid, flags=zmq.SNDMORE, copy=False)
socket.send(b"""HTTP/1.0 200 OK
Content-Type: text/plain
Content-Length: 13
Hello, world!
""", flags=zmq.SNDMORE, copy=False);
socket.send(clientid, flags=zmq.SNDMORE, copy=False)
socket.send(b'',flags=zmq.SNDMORE, copy=False)
print "message sent, waiting for new one!"
except KeyboardInterrupt:
print "SIGINT received, shutting down server..."
socket.close()
context.destroy()
break;
except Exception as e:
print "ERROR: unexpected exception ",e
===========
On 20/02/14 10:29, "Goswin von Brederlow" <goswin-v-b at web.de> wrote:
>On Wed, Feb 19, 2014 at 09:50:57AM +0000, Virgil Palanciuc wrote:
>> Hi all,
>>
>> I¹m trying to re-create the ³HTTP server² example using PYZMQ.
>> My zmq version(s) are:
>> Current libzmq version is 4.0.3
>> Current pyzmq version is 14.0.1
>>
>> My first attempt is listed at the end of email. It kinda¹ works, but I
>> have two questions:
>>
>>
>> 1. For each connection, it prints a message, "Exception
>> zmq.error.ZMQError: ZMQError('Bad address') in
>> <zmq.backend.cython.message.Frame object at 0x10fbc35f0> ignored². Is
>> there something I did wrong, or is this something that is fixed in a
>>more
>> recent version of libzmq/pyzmq?
>
>I didn't get that and I should have the same versions.
>
>> 2. How can one handle ³keep-alive² HTTP connections? If I don¹t send the
>> empty message, no response is sent back; but if I send it, the
>>connection
>> is immediately closed.
>
>With ZMQ_STREAM all data must be send with SNDMORE and in pairs of id
>+ data. So socket.send_multipart isn't allowed.
>
>MfG
> Goswin
>_______________________________________________
>zeromq-dev mailing list
>zeromq-dev at lists.zeromq.org
>http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list