问题
The project is to build a messaging mechanism between a Python and C# program via ZeroMQ .
I want messages to be able to travel in/out from both ends at any time, which is NOT a basic request-reply model a.k.a. REQ/REP
.
One way I can think of is to build a PUB/SUB
model on two ports, i.e. two one way channels.
Is there any method to get a real duplex channel?
回答1:
There are several ways to do this with ZeroMQ. I suggest using a DEALER/ROUTER socket pair:
- Choose one program to be the "server", the other the "client".
- The server will bind a ROUTER socket on a port.
- The client will connect a DEALER socket to the server's ROUTER port. (Note: this implies that the client must know the server's IP and port in advance.)
At this point the client can send messages to the server, but the server has no way to send to the client.
- The client sends a "HELLO" message to the server.
The server will receive a message that includes the client's address and the HELLO message. Now the server can send messages to the client using the client's address.
DEALER/ROUTER is considered an "advanced" socket pair in ZeroMQ. My description here is very high level. You'll really need to read the docs to get the most out of ZeroMQ.
回答2:
Oh yes, Sir!
Use the PAIR-PAIR
or even the XREQ-XREP
ought make it.
The best next step is to carefully read the respective Scalable Formal Communication Pattern archetypes' access-points' API documentation, so as to cross-check, that all pieces of pre-wired behavioural logic meet your Project needs and voilá, harness them in your messaging setup and tune-up the settings so as to meet you performance and latency needs.
That is this simple ( thanks to all the genuine knowhow hidden in these builtins ).
Using for years this very sort of inter-platforms integration among Python + C/MQL4 and other computing nodes, so well worth one's time to learn the powers and strengths of ZeroMQ.
来源:https://stackoverflow.com/questions/44623187/is-there-any-way-to-achieve-a-zeromq-fullduplex-channel