繁体   English   中英

Python ZeroMQ REQ / REP客户端绑定永远等待

[英]Python ZeroMQ REQ/REP client bind waiting forever

我只是在python中尝试使用zeromq进行项目。 我正在尝试绑定“客户端”并将服务器连接到固定位置。 我有一个简单的REQ / REP设置,在本地工作正常,但似乎无法在网络上做任何事情。 如果我反转绑定,那么这也适用于网络。

相关代码是:

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)

这里有一个(非)工作示例: https//gist.github.com/4071783

连接到远程地址时,似乎什么也没发生。 如果我查看tcpdump,我当然可以看到端口上的活动:

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

但是send()recv()仍然被阻塞,好像在等待连接一样。 有谁知道这是什么或可能建议如何调试它?

你可以ping远程地址吗? 0MQ只是在此级别使用TCP,因此如果连接失败,那是因为您尝试连接的地址无法访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM