1MODBUS_TCP_LISTEN(3) Libmodbus Manual MODBUS_TCP_LISTEN(3)
2
3
4
6 modbus_tcp_listen - create and listen a TCP Modbus socket
7
9 int modbus_tcp_listen(modbus_t *ctx, int nb_connection);
10
12 The modbus_tcp_listen() function shall create a socket and listen for
13 nb_connection incoming connections.
14
16 The modbus_tcp_listen() function shall return a new socket if
17 successful. Otherwise it shall return -1 and set errno.
18
20 For a detailed example, see source file bandwith-server-many-up.c
21 provided in tests directory.
22
23 ...
24
25 ctx = modbus_new_tcp("127.0.0.1", 502);
26 if (modbus_connect(ctx) == -1) {
27 fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
28 modbus_free(ctx);
29 return -1;
30 }
31
32 /* Handle until 10 established connections */
33 server_socket = modbus_tcp_listen(ctx, 10);
34
35 /* Clear the reference set of socket */
36 FD_ZERO(&refset);
37
38 /* Add the server socket */
39 FD_SET(server_socket, &refset);
40
41 if (select(server_socket + 1, &refset, NULL, NULL, NULL) == -1) {
42 }
43
44 ...
45
46 close(server_socket);
47 modbus_free(ctx);
48
50 modbus_tcp_accept(3) modbus_tcp_pi_accept(3) modbus_tcp_pi_listen(3)
51
53 The libmodbus documentation was written by Stéphane Raimbault
54 <stephane.raimbault@gmail.com[1]>
55
57 1. stephane.raimbault@gmail.com
58 mailto:stephane.raimbault@gmail.com
59
60
61
62libmodbus 3.0.6 04/02/2014 MODBUS_TCP_LISTEN(3)