First point: zmq.NULL
is the ZMQ_NULL
constant, for use in zeromq's security mechanism. For example:
socket.mechanism = zmq.NULL # or zmq.PLAIN or zmq.CURVE
It is not the NULL
special C constant.
To send an empty message, simply send an empty bytestring:
socket.send(b'')
The second point is that you need to send the empty frame as a separate message, which you are not doing. Here is a working example:
def http_hello_world():
ctx = zmq.Context()
sock = ctx.socket(zmq.ROUTER)
sock.router_raw = True
sock.bind("tcp://*:8080")
while True:
id_bytes, request = sock.recv_multipart()
print("id: %r" % id_bytes)
print("request:", request.decode('utf8'))
if b'/close' in request:
return
# send the body of the response
sock.send_multipart([
id_bytes,
b"""HTTP/1.0 200 OK
Content-Type: text/plain
Hello, world!
"""
])
# send an empty message to finish the response
sock.send_multipart([
id_bytes,
b''
])
By the way, a comment in Github entry shows that it may not close the connection to the client even in C. How can I ask the remote client to close its connection (in Python) ?
I think, as long as you send the empty frame to terminate the message, connections should be closed.