1ZMQ_SENDMSG(3) 0MQ Manual ZMQ_SENDMSG(3)
2
3
4
6 zmq_sendmsg - send a message part on a socket
7
9 int zmq_sendmsg (void *socket, zmq_msg_t *msg, int flags);
10
12 The zmq_sendmsg() function shall queue the message referenced by the
13 msg argument to be sent to the socket referenced by the socket
14 argument. The flags argument is a combination of the flags defined
15 below:
16
17 ZMQ_DONTWAIT
18 For socket types (DEALER, PUSH) that block (either with
19 ZMQ_IMMEDIATE option set and no peer available, or all peers having
20 full high-water mark), specifies that the operation should be
21 performed in non-blocking mode. If the message cannot be queued on
22 the socket, the zmq_sendmsg() function shall fail with errno set to
23 EAGAIN.
24
25 ZMQ_SNDMORE
26 Specifies that the message being sent is a multi-part message, and
27 that further message parts are to follow. Refer to the section
28 regarding multi-part messages below for a detailed description.
29
30 The zmq_msg_t structure passed to zmq_sendmsg() is nullified during the
31 call. If you want to send the same message to multiple sockets you have
32 to copy it (e.g. using zmq_msg_copy()).
33
34 Note
35 A successful invocation of zmq_sendmsg() does not indicate that the
36 message has been transmitted to the network, only that it has been
37 queued on the socket and 0MQ has assumed responsibility for the
38 message.
39
40 Note
41 this API method is deprecated in favor of zmq_msg_send(3).
42
43 Multi-part messages
44 A 0MQ message is composed of 1 or more message parts. Each message part
45 is an independent zmq_msg_t in its own right. 0MQ ensures atomic
46 delivery of messages: peers shall receive either all message parts of a
47 message or none at all. The total number of message parts is unlimited
48 except by available memory.
49
50 An application that sends multi-part messages must use the ZMQ_SNDMORE
51 flag when sending each message part except the final one.
52
54 The zmq_sendmsg() function shall return number of bytes in the message
55 if successful. Otherwise it shall return -1 and set errno to one of the
56 values defined below.
57
59 EAGAIN
60 Non-blocking mode was requested and the message cannot be sent at
61 the moment.
62
63 ENOTSUP
64 The zmq_sendmsg() operation is not supported by this socket type.
65
66 EINVAL
67 The sender tried to send multipart data, which the socket type does
68 not allow.
69
70 EFSM
71 The zmq_sendmsg() operation cannot be performed on this socket at
72 the moment due to the socket not being in the appropriate state.
73 This error may occur with socket types that switch between several
74 states, such as ZMQ_REP. See the messaging patterns section of
75 zmq_socket(3) for more information.
76
77 ETERM
78 The 0MQ context associated with the specified socket was
79 terminated.
80
81 ENOTSOCK
82 The provided socket was invalid.
83
84 EINTR
85 The operation was interrupted by delivery of a signal before the
86 message was sent.
87
88 EFAULT
89 Invalid message.
90
91 EHOSTUNREACH
92 The message cannot be routed.
93
95 Filling in a message and sending it to a socket.
96
97 /* Create a new message, allocating 6 bytes for message content */
98 zmq_msg_t msg;
99 int rc = zmq_msg_init_size (&msg, 6);
100 assert (rc == 0);
101 /* Fill in message content with 'AAAAAA' */
102 memset (zmq_msg_data (&msg), 'A', 6);
103 /* Send the message to the socket */
104 rc = zmq_sendmsg (socket, &msg, 0);
105 assert (rc == 6);
106
107 Sending a multi-part message.
108
109 /* Send a multi-part message consisting of three parts to socket */
110 rc = zmq_sendmsg (socket, &part1, ZMQ_SNDMORE);
111 rc = zmq_sendmsg (socket, &part2, ZMQ_SNDMORE);
112 /* Final part; no more parts to follow */
113 rc = zmq_sendmsg (socket, &part3, 0);
114
115
117 zmq_recv(3) zmq_socket(7) zmq(7)
118
120 This page was written by the 0MQ community. To make a change please
121 read the 0MQ Contribution Policy at
122 http://www.zeromq.org/docs:contributing.
123
124
125
1260MQ 4.3.4 01/21/2023 ZMQ_SENDMSG(3)