1ZMQ_TCP(7) 0MQ Manual ZMQ_TCP(7)
2
3
4
6 zmq_tcp - 0MQ unicast transport using TCP
7
9 TCP is an ubiquitous, reliable, unicast transport. When connecting
10 distributed applications over a network with 0MQ, using the TCP
11 transport will likely be your first choice.
12
14 A 0MQ address string consists of two parts as follows:
15 transport://endpoint. The transport part specifies the underlying
16 transport protocol to use, and for the TCP transport shall be set to
17 tcp. The meaning of the endpoint part for the TCP transport is defined
18 below.
19
20 Assigning a local address to a socket
21 When assigning a local address to a socket using zmq_bind() with the
22 tcp transport, the endpoint shall be interpreted as an interface
23 followed by a colon and the TCP port number to use.
24
25 An interface may be specified by either of the following:
26
27 · The wild-card *, meaning all available interfaces.
28
29 · The primary IPv4 address assigned to the interface, in its numeric
30 representation.
31
32 · The interface name as defined by the operating system.
33
34 Note
35 Interface names are not standardised in any way and should be
36 assumed to be arbitrary and platform dependent. On Win32 platforms
37 no short interface names exist, thus only the primary IPv4 address
38 may be used to specify an interface.
39
40 Connecting a socket
41 When connecting a socket to a peer address using zmq_connect() with the
42 tcp transport, the endpoint shall be interpreted as a peer address
43 followed by a colon and the TCP port number to use.
44
45 A peer address may be specified by either of the following:
46
47 · The DNS name of the peer.
48
49 · The IPv4 address of the peer, in it’s numeric representation.
50
52 0MQ messages are transmitted over TCP in frames consisting of an
53 encoded payload length, followed by a flags field and the message body.
54 The payload length is defined as the combined length in octets of the
55 message body and the flags field.
56
57 For frames with a payload length not exceeding 254 octets, the payload
58 length shall be encoded as a single octet. The minimum valid payload
59 length of a frame is 1 octet, thus a payload length of 0 octets is
60 invalid and such frames SHOULD be ignored.
61
62 For frames with a payload length exceeding 254 octets, the payload
63 length shall be encoded as a single octet with the value 255 followed
64 by the payload length represented as a 64-bit unsigned integer in
65 network byte order.
66
67 The flags field consists of a single octet containing various control
68 flags:
69
70 Bit 0 (MORE): More message parts to follow. A value of 0 indicates that
71 there are no more message parts to follow; or that the message being
72 sent is not a multi-part message. A value of 1 indicates that the
73 message being sent is a multi-part message and more message parts are
74 to follow.
75
76 Bits 1-7: Reserved. Bits 1-7 are reserved for future expansion and MUST
77 be set to zero.
78
79 The following ABNF grammar represents a single frame:
80
81 frame = (length flags data)
82 length = OCTET / (escape 8OCTET)
83 flags = OCTET
84 escape = %xFF
85 data = *OCTET
86
87 The following diagram illustrates the layout of a frame with a payload
88 length not exceeding 254 octets:
89
90 0 1 2 3
91 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
92 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
93 | Payload length| Flags | Message body ... |
94 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95 | Message body ...
96 +-+-+-+-+-+-+- ...
97
98 The following diagram illustrates the layout of a frame with a payload
99 length exceeding 254 octets:
100
101 0 1 2 3
102 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
103 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104 | 0xff | Payload length ... |
105 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106 | Payload length ... |
107 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108 | Payload length| Flags | Message body ... |
109 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110 | Message body ...
111 +-+-+-+-+-+-+-+ ...
112
114 Assigning a local address to a socket.
115
116 /* TCP port 5555 on all available interfaces */
117 rc = zmq_bind(socket, "tcp://*:5555");
118 assert (rc == 0);
119 /* TCP port 5555 on the local loop-back interface on all platforms */
120 rc = zmq_bind(socket, "tcp://127.0.0.1:5555");
121 assert (rc == 0);
122 /* TCP port 5555 on the first Ethernet network interface on Linux */
123 rc = zmq_bind(socket, "tcp://eth0:5555");
124 assert (rc == 0);
125
126 Connecting a socket.
127
128 /* Connecting using an IP address */
129 rc = zmq_connect(socket, "tcp://192.168.1.1:5555");
130 assert (rc == 0);
131 /* Connecting using a DNS name */
132 rc = zmq_connect(socket, "tcp://server1:5555");
133 assert (rc == 0);
134
135
137 zmq_bind(3) zmq_connect(3) zmq_pgm(7) zmq_ipc(7) zmq_inproc(7) zmq(7)
138
140 This 0MQ manual page was written by Martin Sustrik
141 <sustrik@250bpm.com[1]> and Martin Lucina <mato@kotelna.sk[2]>.
142
144 1. sustrik@250bpm.com
145 mailto:sustrik@250bpm.com
146
147 2. mato@kotelna.sk
148 mailto:mato@kotelna.sk
149
150
151
1520MQ 2.1.4 03/30/2011 ZMQ_TCP(7)