1MODBUS_TCP_PI_LISTEN(3)        libmodbus Manual        MODBUS_TCP_PI_LISTEN(3)
2
3
4

NAME

6       modbus_tcp_pi_listen - create and listen a TCP PI Modbus socket (IPv6)
7

SYNOPSIS

9       int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection);
10

DESCRIPTION

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

RETURN VALUE

19       The function shall return a new socket if successful. Otherwise it
20       shall return -1 and set errno.
21

EXAMPLE

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

SEE ALSO

45       modbus_new_tcp_pi(3) modbus_tcp_pi_accept(3) modbus_tcp_listen(3)
46

AUTHORS

48       The libmodbus documentation was written by Stéphane Raimbault
49       <stephane.raimbault@gmail.com>
50
51
52
53libmodbus v3.1.7                  07/20/2023           MODBUS_TCP_PI_LISTEN(3)
Impressum