参考http://hintjens.wdfiles.com/local--files/main:files/cc1pe.pdf 第22页分而治之
Ventilator[PUSH]
___________________|____________________
| | |
[PULL]Worker[PUSH] [PULL]Worker[PUSH] [PULL]Worker[PUSH]
|__________________|___________________|
|
[PULL]Sink
// taskvent.c
// Socket to send messages on
void *context = zmq_ctx_new ();
void *sender = zmq_socket (context, ZMQ_PUSH);
zmq_bind (sender, "tcp://*:5557");
// Socket to send start of batch message on
void *sink = zmq_socket (context, ZMQ_PUSH);
zmq_connect (sink, "tcp://localhost:5558");
// taskwork.c
// Socket to receive messages on
void *context = zmq_ctx_new ();
void *receiver = zmq_socket (context, ZMQ_PULL);
zmq_connect (receiver, "tcp://localhost:5557");
// Socket to send messages to
void *sender = zmq_socket (context, ZMQ_PUSH);
zmq_connect (sender, "tcp://localhost:5558");
// tasksink.c
// Prepare our context and socket
void *context = zmq_ctx_new ();
void *receiver = zmq_socket (context, ZMQ_PULL);
zmq_bind (receiver, "tcp://*:5558");
我对何时使用 zmq_bind 或 zmq_connect 感到困惑。它说大多数时候“服务器”使用 zmq_bind 而“客户端”使用 zmq_connect。
Question> 什么时候应该使用zmq_bind,什么时候应该使用zmq_connect?
zmq_bind - accept incoming connections on a socket
zmq_connect - create outgoing connection from socket