3
我的(Python)的出版商:爲什麼我的C++ ZeroMQ訂戶沒有收到任何數據?
import zmq
import time
context = zmq.Context()
socket = context.socket(zmq.PUB)
connectStr = "tcp://*:%d" % 5563
socket.bind(connectStr)
messageNum = 0
while True:
++messageNum
message = "Testing %d"%messageNum
print("Sending.. '%s'"%message)
socket.send_string(message)
time.sleep(1)
messageNum += 1
我的(C++)的用戶(在GTEST運行):
TEST(ZeroMqPubSubTest, SubscribeGetsData)
{
// Set up the subscriber we'll use to receive the message.
zmq::context_t context;
zmq::socket_t subscriber(context, ZMQ_SUB);
// Connect to the publisher
subscriber.connect("tcp://127.0.0.1:5563");
subscriber.setsockopt(ZMQ_SUBSCRIBE, ""); // Set the filter blank so we receive everything
zmq::message_t response(0);
EXPECT_TRUE(subscriber.recv(&response));
}
我開始了出版商然後啓動用戶。後者永遠不會回來。
如果我運行一個Python用戶做的(我認爲)完全一樣的東西..
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect ("tcp://127.0.0.1:5563")
socket.setsockopt_string(zmq.SUBSCRIBE, "")
print ("Waiting for data...")
while True:
message = socket.recv()
print ("Got some data:",message)
..它工作正常:
等待數據...
得到一些數據:b'Testing 8'
得到一些數據:b'Testing 9'
點上@kazemakase。我仍然在學習ZeroMQ的精妙之處,看起來特別是cpp接口的幾個方面有幾個問題。 –