modbus_tcp_listen.txt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. modbus_tcp_listen(3)
  2. ====================
  3. NAME
  4. ----
  5. modbus_tcp_listen - create and listen a TCP Modbus socket (IPv4)
  6. SYNOPSIS
  7. --------
  8. *int modbus_tcp_listen(modbus_t *'ctx', int 'nb_connection');*
  9. DESCRIPTION
  10. -----------
  11. The _modbus_tcp_listen()_ function shall create a socket and listen for
  12. 'nb_connection' incoming connections.
  13. RETURN VALUE
  14. ------------
  15. The _modbus_tcp_listen()_ function shall return a new socket if
  16. successful. Otherwise it shall return -1 and set errno.
  17. EXAMPLE
  18. -------
  19. For detailed examples, see source files in tests directory:
  20. - unit-test-server.c, simple but handle only one connection
  21. - bandwith-server-many-up.c, handles several connections at once
  22. [source,c]
  23. -------------------
  24. ...
  25. ctx = modbus_new_tcp("127.0.0.1", 502);
  26. /* Handle until 10 established connections */
  27. server_socket = modbus_tcp_listen(ctx, 10);
  28. /* Clear the reference set of socket */
  29. FD_ZERO(&refset);
  30. /* Add the server socket */
  31. FD_SET(server_socket, &refset);
  32. if (select(server_socket + 1, &refset, NULL, NULL, NULL) == -1) {
  33. }
  34. ...
  35. close(server_socket);
  36. modbus_free(ctx);
  37. -------------------
  38. SEE ALSO
  39. --------
  40. linkmb:modbus_tcp_accept[3]
  41. linkmb:modbus_tcp_pi_accept[3]
  42. linkmb:modbus_tcp_pi_listen[3]
  43. AUTHORS
  44. -------
  45. The libmodbus documentation was written by Stéphane Raimbault
  46. <stephane.raimbault@gmail.com>