我已經編譯了libzmq和openpgm,沒有在windows下進行更改。此處的代碼取自ZeroMQ Guide(「天氣出版商」服務器/客戶端)。但是,如果我將「tcp」更改爲「epgm」,它將不再工作(數據未收到,但連接已建立)。ZeroMQ的EPGM不能在天氣工作PUB-SUB演示
void test_serv()
{
// Prepare our context and publisher
void *context = zmq_ctx_new();
void *publisher = zmq_socket(context, ZMQ_PUB);
int rc = zmq_bind(publisher, "epgm://127.0.0.1:5556");
assert(rc == 0);
// Initialize random number generator
srandom((unsigned)time(NULL));
while (!stop_server)
{
// Get values that will fool the boss
int zipcode, temperature, relhumidity;
zipcode = randof(1000) + 600;
temperature = randof(215) - 80;
relhumidity = randof(50) + 10;
// Send message to all subscribers
char update[20];
sprintf(update, "%d %d %d", zipcode, temperature, relhumidity);
s_send(publisher, update);
}
LOG("END Server shutdown");
Sleep(500);
zmq_close(publisher);
zmq_ctx_destroy(context);
}
void test_sock()
{
// Socket to talk to server
LOG("Collecting updates from weather server...");
void *context = zmq_ctx_new();
void *subscriber = zmq_socket(context, ZMQ_SUB);
int rc = zmq_connect(subscriber, "epgm://127.0.0.1:5556");
assert(rc == 0);
// Subscribe to zipcode, default is NYC, 10001
char *filter = "1001 ";
rc = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE,
filter, strlen(filter));
assert(rc == 0);
// Process 100 updates
int update_nbr;
long total_temp = 0;
for (update_nbr = 0; update_nbr < 10; update_nbr++) {
char *string = s_recv(subscriber);
int zipcode, temperature, relhumidity;
sscanf(string, "%d %d %d",
&zipcode, &temperature, &relhumidity);
total_temp += temperature;
LOG(">> " << string);
free(string);
}
LOG("Average temperature for zipcode "<< filter << "was " << (int)(total_temp/update_nbr) << 'F');
zmq_close(subscriber);
zmq_ctx_destroy(context);
}
我在不同的線程中運行兩個函數,tcp任何東西都按預期工作。
我已經嘗試使用cmd.exe並使用接口IP(192.168.137.64)作爲前綴而不是「eth0」,如RFC:epgm://192.168.137.64; 127.0中所示,使用「route print 0.0.0.0」。 0.1:5556連接和/或綁定,但是這打破了我的套接字並引發錯誤。
此外,「PGM」需要管理員權限,我現在無法對其進行測試。
錯誤不是「不支持協議」 errno設置爲B(11),我不明白它是什麼意思(沒有文檔)。
我不確定你的意思是'loopback capture interface support'。你能澄清一下嗎? – Croll