1MODBUS_TCP_PI_LISTEN(3) libmodbus Manual MODBUS_TCP_PI_LISTEN(3)
2
3
4
6 modbus_tcp_pi_listen - create and listen a TCP PI Modbus socket (IPv6)
7
9 int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection);
10
12 The modbus_tcp_pi_listen() function shall create a socket and listen to
13 maximum nb_connection incoming connections on the specified nodes. The
14 context ctx must be allocated and initialized with modbus_new_tcp_pi(3)
15 before to set the node to listen, if node is set to NULL or 0.0.0.0,
16 any addresses will be listen.
17
19 The function shall return a new socket if successful. Otherwise it
20 shall return -1 and set errno.
21
23 For detailed examples, see source files in tests directory:
24
25 • unit-test-server.c, simple but handle only one connection
26
27 ...
28
29 ctx = modbus_new_tcp_pi("::0", "502");
30 s = modbus_tcp_pi_listen(ctx, 1);
31 modbus_tcp_pi_accept(ctx, &s);
32
33 for (;;) {
34 rc = modbus_receive(ctx, query);
35 modbus_replay(ctx, query, rc, mb_mapping);
36 }
37 ...
38
39 mclose(s);
40 modbus_free(ctx);
41
42 • bandwidth-server-many-up.c, handles several connections at once
43
45 modbus_new_tcp_pi(3) modbus_tcp_pi_accept(3) modbus_tcp_listen(3)
46
48 The libmodbus documentation was written by Stéphane Raimbault
49 <stephane.raimbault@gmail.com>
50
51
52
53libmodbus v3.1.6 02/04/2022 MODBUS_TCP_PI_LISTEN(3)