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

NAME

6       modbus_set_socket - set socket of the context
7

SYNOPSIS

9       int modbus_set_socket(modbus_t *ctx, int s);
10

DESCRIPTION

12       The modbus_set_socket() function shall set the socket or file
13       descriptor in the libmodbus context. This function is useful for
14       managing multiple client connections to the same server.
15

RETURN VALUE

17       The function shall return 0 if successful. Otherwise it shall return -1
18       and set errno.
19

EXAMPLE

21           ctx = modbus_new_tcp("127.0.0.1", 1502);
22           server_socket = modbus_tcp_listen(ctx, NB_CONNECTION);
23
24           FD_ZERO(&rdset);
25           FD_SET(server_socket, &rdset);
26
27           /* .... */
28
29           if (FD_ISSET(master_socket, &rdset)) {
30               modbus_set_socket(ctx, master_socket);
31               rc = modbus_receive(ctx, query);
32               if (rc != -1) {
33                   modbus_reply(ctx, query, rc, mb_mapping);
34               }
35           }
36

SEE ALSO

38       modbus_get_socket(3)
39

AUTHORS

41       The libmodbus documentation was written by Stéphane Raimbault
42       <stephane.raimbault@gmail.com>
43
44
45
46libmodbus v3.1.6                  01/19/2023              MODBUS_SET_SOCKET(3)
Impressum