我正在尝试使用带有NetMQ +控制套接字的XPUB / XSUB模式实现集线器(以控制集线器的行为)。我使用代理,NetMqPoller,并希望使用控制套接字。但无论我尝试什么 - 它都行不通。这是我的代码,任何想法为什么它不起作用?
Using xpubSocket As New XPublisherSocket("@tcp://127.0.0.1:1234")
Using xsubSocket As New XSubscriberSocket("@tcp://127.0.0.1:5678")
Using plr As New NetMQPoller()
Using ctrlIn As New StreamSocket(">tcp://127.0.0.1:5678")
AddHandler ctrlIn.ReceiveReady, AddressOf ctrlIn_ReceiveReady
plr.Add(xpubSocket)
plr.Add(xsubSocket)
plr.Add(ctrlIn)
Dim proxy As New Proxy(xsubSocket, xpubSocket, ctrlIn, plr)
proxy.Start()
plr.Run()
End Using
End Using
End Using
End Using
还有一个方法,每次ctrlIn套接字接收数据时运行:
Sub ctrlIn_ReceiveReady(sender As Object, e As NetMQSocketEventArgs)
Dim bytes() As Byte
While (e.Socket.TryReceiveFrameBytes(bytes))
Console.WriteLine("Received {0} bytes.", bytes.Length)
End While
End Sub
现在简短说明:集线器(XPUB / XSUB)工作正常,即当我启动发布者和订阅者时 - 我可以看到消息流动。但控制套接字不起作用,我得到的只有两条消息:
Received 5 bytes.
Received 10 bytes.
然后 - 控制套接字保持静默,不再有字节流过它。 有谁知道我哪里错了?或者也许任何人都可以指出一个有效的例子?我一直在寻找一个例子,但是找不到任何控件套接字工作。
答案 0 :(得分:0)
为什么Stream类型的控件套接字?此外,您应该在控件插槽的另一端有另一个插槽,现在您将Stream类型的控件插槽连接到Publisher,Stream和Publisher无法相互通信。
尝试这样的事情(抱歉语法错误,不是VB开发人员)
Using xpubSocket As New XPublisherSocket("@tcp://127.0.0.1:1234")
Using xsubSocket As New XSubscriberSocket("@tcp://127.0.0.1:5678")
Using plr As New NetMQPoller()
Using ctrlOut As New Dealer("@inproc://control")
Using ctrlIn As New Dealer(">inproc://control")
AddHandler ctrlIn.ReceiveReady, AddressOf ctrlIn_ReceiveReady
plr.Add(xpubSocket)
plr.Add(xsubSocket)
plr.Add(ctrlIn)
Dim proxy As New Proxy(xsubSocket, xpubSocket, ctrlOut, plr)
proxy.Start()
plr.Run()
End Using
End Using
End Using
End Using