我的环境:python 2.7,pyzmq-13.1.0-py2.7-win32,windows 7 sp1 x64
但是在C#代码下没有任何问题,它有什么问题?
python代码:
import time
import struct
import zmq
import threading
def relay(contextBind):
backend = contextBind.socket(zmq.ROUTER)
identity = '2'
backend.setsockopt(zmq.IDENTITY, identity )
backend.bind('tcp://*:5678')
poller = zmq.Poller()
poller.register(backend, zmq.POLLIN)
while True:
try:
sockets = dict(poller.poll())
except Exception,ex:
print ex
break
if backend in sockets:
if sockets[backend] == zmq.POLLIN:
msg = backend.recv_multipart()
print msg
if __name__ == '__main__':
#the first message is lost
context = zmq.Context()
relayThread = threading.Thread(target=relay, args=(context,))
relayThread.start()
frontend = context.socket(zmq.ROUTER)
identity = '3'
frontend.setsockopt(zmq.IDENTITY, identity )
try:
frontend.connect('tcp://127.0.0.1:5678')
except zmq.error.ZMQError, ex:
print ex
i = 1
while True:
print 'send ', str(i),'\n'
frontend.send('2', zmq.SNDMORE)
frontend.send(str(i) + ' msg')
i = i + 1
time.sleep(1)