zmq_socket - create 0MQ socket
void *zmq_socket (void *context, int type);
The zmq_socket() function shall create a ØMQ socket within the specified context and return an opaque handle to the newly created socket. The type argument specifies the socket type, which determines the semantics of communication over the socket.
The following messaging patterns are defined:
The simplest messaging pattern, used for communicating between two peers.
ZMQ_P2P
ZMQ_P2P
A socket of type ZMQ_P2P can only be connected to a single peer at any one time. No message routing or filtering is performed on messages sent over a ZMQ_P2P socket.
The publish-subscribe pattern is used for one-to-many distribution of data from a single publisher to multiple subscribers in a fanout fashion.
ZMQ_PUB
ZMQ_SUB
A socket of type ZMQ_PUB is used by a publisher to distribute data. Messages sent are distributed in a fanout fashion to all connected peers. The zmq_recv() function is not implemented for this socket type.
ZMQ_SUB
ZMQ_PUB
A socket of type ZMQ_SUB is used by a subscriber to subscribe to data distributed by a publisher. Initially a ZMQ_SUB socket is not subscribed to any messages, use the ZMQ_SUBSCRIBE option of zmq_setsockopt() to specify which messages to subscribe to. The zmq_send() function is not implemented for this socket type.
The request-reply pattern is used for sending requests from a client to a service, and receiving subsequent replies to each request sent.
ZMQ_REQ
ZMQ_REP
A socket of type ZMQ_REQ is used by a client to send requests to and receive replies from a service. This socket type allows only an alternating sequence of zmq_send(request) and subsequent zmq_recv(reply) calls. Each request sent is load-balanced among all connected services.
ZMQ_REP
ZMQ_REQ
A socket of type ZMQ_REP is used by a service to receive requests from and send replies to a client. This socket type allows only an alternating sequence of zmq_recv(request) and subsequent zmq_send(reply) calls. Each reply is routed to the client that issued the last received request.
The parallelized pipeline pattern is used for distributing work between components of a pipeline. Work travels down the pipeline and at each stage can be processed by any number of components in parallel.
ZMQ_UPSTREAM
ZMQ_DOWNSTREAM
A socket of type ZMQ_UPSTREAM is used by a component of a pipeline to receive messages from upstream stages of the pipeline. Messages are fair-queued from among all connected upstream components. The zmq_send() function is not implemented for this socket type.
ZMQ_DOWNSTREAM
ZMQ_UPSTREAM
A socket of type ZMQ_DOWNSTREAM is used by a component of a pipeline to send messages to downstream stages of the pipeline. Messages are load-balanced to all connected downstream components. The zmq_recv() function is not implemented for this socket type.
The zmq_socket() function shall return an opaque handle to the newly created socket if successful. Otherwise, it shall return NULL and set errno to one of the values defined below.
The requested socket type is invalid.
The number of application threads using sockets within this context has been exceeded. See the app_threads parameter of the zmq_init() function.
The ØMQ documentation was written by Martin Sustrik <sustrik@250bpm.com> and Martin Lucina <mato@kotelna.sk>.