5 modbus_tcp_listen - create and listen a TCP Modbus socket (IPv4)
10 int modbus_tcp_listen(modbus_t *ctx, int nb_connection);
15 The *modbus_tcp_listen()* function shall create a socket and listen to maximum
16 `nb_connection` incoming connections on the specified IP address. The context
17 `ctx` must be allocated and initialized with [modbus_new_tcp](modbus_new_tcp.md) before to
18 set the IP address to listen, if IP address is set to NULL or '0.0.0.0', any addresses will be
23 The function shall return a new socket if successful. Otherwise it shall return
28 For detailed examples, see source files in tests directory:
30 - unit-test-server.c, simple but handle only one connection
31 - bandwidth-server-many-up.c, handles several connections at once
36 /* To listen any addresses on port 502 */
37 ctx = modbus_new_tcp(NULL, 502);
39 /* Handle until 10 established connections */
40 server_socket = modbus_tcp_listen(ctx, 10);
42 /* Clear the reference set of socket */
45 /* Add the server socket */
46 FD_SET(server_socket, &refset);
48 if (select(server_socket + 1, &refset, NULL, NULL, NULL) == -1) {
59 - [modbus_new_tcp](modbus_new_tcp.md)
60 - [modbus_tcp_accept](modbus_tcp_accept.md)
61 - [modbus_tcp_pi_listen](modbus_tcp_pi_listen.md)