modbus_tcp_listen.txt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. modbus_tcp_listen(3)
  2. ====================
  3. NAME
  4. ----
  5. modbus_tcp_listen - create and listen a TCP Modbus socket
  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 a detailed example, see source file bandwith-server-many-up.c provided in
  20. tests directory.
  21. [source,c]
  22. -------------------
  23. ...
  24. ctx = modbus_new_tcp("127.0.0.1", 502);
  25. if (modbus_connect(ctx) == -1) {
  26. fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
  27. modbus_free(ctx);
  28. return -1;
  29. }
  30. /* Handle until 10 established connections */
  31. server_socket = modbus_tcp_listen(ctx, 10);
  32. /* Clear the reference set of socket */
  33. FD_ZERO(&refset);
  34. /* Add the server socket */
  35. FD_SET(server_socket, &refset);
  36. if (select(server_socket + 1, &refset, NULL, NULL, NULL) == -1) {
  37. }
  38. ...
  39. close(server_socket);
  40. modbus_free(ctx);
  41. -------------------
  42. SEE ALSO
  43. --------
  44. linkmb:modbus_tcp_accept[3]
  45. linkmb:modbus_tcp_pi_accept[3]
  46. linkmb:modbus_tcp_pi_listen[3]
  47. AUTHORS
  48. -------
  49. The libmodbus documentation was written by Stéphane Raimbault
  50. <stephane.raimbault@gmail.com>