Morphit
Morphit

Reputation: 376

Python ZeroMQ REQ/REP client bind waiting forever

I'm just trying out zeromq for a project in python. I'm trying to bind the 'client' side and connect the server to the fixed location. I have a simple REQ/REP setup that works fine locally but seems to do nothing over a network. If I reverse the binding, then this also works over the network.

The relevant code is:

def respond(sock):
    message = sock.recv()
    response = "world"
    sock.send(response)
    print("Received '{0:s}', sent '{1:s}'.".format(message, response) )

def request(sock):
    message = "Hello"
    sock.send(message)
    response = sock.recv()
    print("Sent '{0:s}', recieved '{1:s}'".format(message, response) )

def main():
    opts = get_opts()
    if opts.client:
        sock = CONTEXT.socket(zmq.REQ)
        sock.bind("tcp://*:{0:d}".format(opts.port) )
        request(sock)
    if opts.server:
        sock = CONTEXT.socket(zmq.REP)
        sock.connect("tcp://{0:s}:{1:d}".format(opts.address, opts.port) )
        while True:
            respond(sock)

And a (non-)working example is here: https://gist.github.com/4071783

When connecting to a remote address, nothing seems to happen. If I check with tcpdump, I can certainly see activity on the port:

12:20:18.846927 IP server.58387 > client.5555: Flags [.], ack 1, win 3650, options [nop,nop,TS val 718051 ecr 46170252], length 0
12:20:18.847156 IP client.5555 > server.58387: Flags [P.], seq 1:3, ack 1, win 227, options [nop,nop,TS val 46170252 ecr 718051], length 2
12:20:18.847349 IP server.58387 > client.5555: Flags [P.], seq 1:3, ack 1, win 3650, options [nop,nop,TS val 718051 ecr 46170252], length 2
12:20:18.847373 IP client.5555 > server.58387: Flags [.], ack 3, win 227, options [nop,nop,TS val 46170252 ecr 718051], length 0
12:20:18.847553 IP client.5555 > server.58387: Flags [P.], seq 3:16, ack 3, win 227, options [nop,nop,TS val 46170252 ecr 718051], length 13
12:20:18.847645 IP server.58387 > client.5555: Flags [.], ack 3, win 3650, options [nop,nop,TS val 718051 ecr 46170252], length 0
12:20:18.848286 IP server.58387 > client.5555: Flags [.], ack 16, win 3650, options [nop,nop,TS val 718051 ecr 46170252], length 0

But the send() and recv() are still blocked as if waiting for a connection. Does anyone know what this is or could suggest how to debug it?

Upvotes: 3

Views: 997

Answers (1)

Pieter Hintjens
Pieter Hintjens

Reputation: 6669

Can you ping the remote address? 0MQ is just using TCP at this level so if the connect fails, it's because the address you're trying to connect to is not reachable.

Upvotes: 1

Related Questions