gpt4 book ai didi

c# - 无法使用 Zeromq PGM 协议(protocol)接收消息

转载 作者:太空狗 更新时间:2023-10-30 00:31:32 26 4
gpt4 key购买 nike

我正在尝试使用 PGM 协议(protocol)创建一个基于服务器/客户端 zeromq 的 PUB-SUB,全部在我的本地计算机上。

出于某种原因,我卡在了:

string a = clientsocket.Receive(Encoding.Unicode);

这只是为了测试,我没有得到异常,程序只是等待。

服务器代码:

var context = ZmqContext.Create();
ZmqSocket serversocket = context.CreateSocket(SocketType.PUB);

try
{
serversocket.Bind("epgm://192.168.137.127;224.0.0.1:5555");
}
catch (ZmqException)
{
throw;
}

int x = 0;
Console.WriteLine("UP");

while (x < 100)
{
serversocket.Send("hello",Encoding.Unicode);
Console.WriteLine("hello sent {0}",x.ToString());
Thread.Sleep(2000);
x++;
}

客户端代码:

context = ZmqContext.Create();
clientsocket = context.CreateSocket(SocketType.SUB);

try
{
clientsocket.Connect("epgm://192.168.137.127;224.0.0.1:5555");
}
catch (ZmqException)
{
throw;
}

clientsocket.SubscribeAll();
clientsocket.ReceiveReady += PollingItemEvens;

string a = clientsocket.Receive(Encoding.Unicode);

if (a == "hello")
{
Application.Run(_form1);
}

var poller = new Poller(new List<ZmqSocket> {clientsocket});

while (true)
{
poller.Poll();
}

编辑 [2014-08-04 1640 UTC+0000]

我在阅读文档后更改了 epgm IP。然而并没有解决问题...

我的 IPv4 是 192.168.137.127

它是笔记本电脑上的热点降神会,有什么不同吗?

我可以在 windwos cmd 的“netstat”上看到 epgm 吗?因为我什么都没看到

最佳答案

你应该看看 pgm/epgm documentation for 0MQ :

特别是:

Connecting a socket

When connecting a socket to a peer address using zmq_connect() with the pgm or epgm transport, the endpoint shall be interpreted as an interface followed by a semicolon, followed by a multicast address, followed by a colon and a port number.

An interface may be specified by either of the following:

•The interface name as defined by the operating system.

•The primary IPv4 address assigned to the interface, in its numeric representation.

Interface names are not standardised in any way and should be assumed to be arbitrary and platform dependent. On Win32 platforms no short interface names exist, thus only the primary IPv4 address may be used to specify an interface.

A multicast address is specified by an IPv4 multicast address in its numeric representation.

如果您遵循文档,地址 "epgm://224.0.0.1:8200" 是无效的:它缺少地址的接口(interface)部分。

关于c# - 无法使用 Zeromq PGM 协议(protocol)接收消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25107729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com