summaryrefslogtreecommitdiff
path: root/doc/zmq_socket.txt
blob: 6cfc72623068ade3e81d3934703aab87a02bb27c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
zmq_socket(3)
=============


NAME
----
zmq_socket - creates 0MQ socket


SYNOPSIS
--------
'void *zmq_socket (void *context, int type);'


DESCRIPTION
-----------
Open a socket within the specified 'context'. To create a context, use
'zmq_init' function. 'type' argument can be one of the values defined below.
Note that each socket is owned by exactly one thread (the one that it was
created from) and should not be used from any other thread.

*ZMQ_P2P*::
Socket to communicate with a single peer. Allows for only a single connect
or a single bind. There's no message routing or message filtering involved.
+
Compatible peer sockets: ZMQ_P2P.

*ZMQ_PUB*::
Socket to distribute data. Recv function is not implemented for this socket
type. Messages are distributed in fanout fashion to all the peers.
+
Compatible peer sockets: ZMQ_SUB.

*ZMQ_SUB*::
Socket to subscribe for data. Send function is not implemented for this socket
type. Initially, socket is subscribed for no messages. Use ZMQ_SUBSCRIBE option
to specify which messages to subscribe for.
+
Compatible peer sockets: ZMQ_PUB.

*ZMQ_REQ*::
Socket to send requests and receive replies. Requests are load-balanced among
all the peers. This socket type allows only an alternated sequence of send's
and recv's.
+
Compatible peer sockets: ZMQ_REP, ZMQ_XREP.

*ZMQ_REP*::
Socket to receive requests and send replies. This socket type allows only an
alternated sequence of recv's and send's. Each send is routed to the peer that
issued the last received request.
+
Compatible peer sockets: ZMQ_REQ, ZMQ_XREQ.

*ZMQ_XREQ*::
Special socket type to be used in request/reply middleboxes such as
linkzmq:zmq_queue[7]. Requests forwarded using this socket type should be
tagged by a proper prefix identifying the original requester. Replies received
by this socket are tagged with a proper postfix that can be use to route the
reply back to the original requester.
+
Compatible peer sockets: ZMQ_REP, ZMQ_XREP.

*ZMQ_XREP*::
Special socket type to be used in request/reply middleboxes such as
linkzmq:zmq_queue[7]. Requests received using this socket are already properly
tagged with prefix identifying the original requester. When sending a reply via
XREP socket the message should be tagged with a prefix from a corresponding
request.
+
Compatible peer sockets: ZMQ_REQ, ZMQ_XREQ.

*ZMQ_UPSTREAM*::
Socket to receive messages from up the stream. Messages are fair-queued from
among all the connected peers. Send function is not implemented for this socket
type.
+
Compatible peer sockets: ZMQ_DOWNSTREAM.

*ZMQ_DOWNSTREAM*::
Socket to send messages down stream. Messages are load-balanced among all the
connected peers. Recv function is not implemented for this socket type.
+
Compatible peer sockets: ZMQ_UPSTREAM.


RETURN VALUE
------------
Function returns socket handle is successful. Otherwise it returns NULL and
sets errno to one of the values below.


ERRORS
------
*EINVAL*::
    invalid socket type.

*EMTHREAD*::
    the number of application threads allowed to own 0MQ sockets was exceeded.
    See 'app_threads' parameter to 'zmq_init' function.


EXAMPLE
-------
----
void *s = zmq_socket (context, ZMQ_PUB);
assert (s);
int rc = zmq_bind (s, "tcp://192.168.0.1:5555");
assert (rc == 0);
----


SEE ALSO
--------
linkzmq:zmq_init[3]
linkzmq:zmq_setsockopt[3]
linkzmq:zmq_bind[3]
linkzmq:zmq_connect[3]
linkzmq:zmq_send[3]
linkzmq:zmq_flush[3]
linkzmq:zmq_recv[3]


AUTHOR
------
Martin Sustrik <sustrik at 250bpm dot com>