'\" t .\" Title: modbus_tcp_listen .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.79.1 .\" Date: 11/30/2016 .\" Manual: Libmodbus Manual .\" Source: libmodbus 3.0.6 .\" Language: English .\" .TH "MODBUS_TCP_LISTEN" "3" "11/30/2016" "libmodbus 3\&.0\&.6" "Libmodbus Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" modbus_tcp_listen \- create and listen a TCP Modbus socket .SH "SYNOPSIS" .sp \fBint modbus_tcp_listen(modbus_t *\fR\fB\fIctx\fR\fR\fB, int \fR\fB\fInb_connection\fR\fR\fB);\fR .SH "DESCRIPTION" .sp The \fImodbus_tcp_listen()\fR function shall create a socket and listen for \fInb_connection\fR incoming connections\&. .SH "RETURN VALUE" .sp The \fImodbus_tcp_listen()\fR function shall return a new socket if successful\&. Otherwise it shall return \-1 and set errno\&. .SH "EXAMPLE" .sp For a detailed example, see source file bandwith\-server\-many\-up\&.c provided in tests directory\&. .sp .if n \{\ .RS 4 .\} .nf \&.\&.\&. ctx = modbus_new_tcp("127\&.0\&.0\&.1", 502); if (modbus_connect(ctx) == \-1) { fprintf(stderr, "Connection failed: %s\en", modbus_strerror(errno)); modbus_free(ctx); return \-1; } /* Handle until 10 established connections */ server_socket = modbus_tcp_listen(ctx, 10); /* Clear the reference set of socket */ FD_ZERO(&refset); /* Add the server socket */ FD_SET(server_socket, &refset); if (select(server_socket + 1, &refset, NULL, NULL, NULL) == \-1) { } \&.\&.\&. close(server_socket); modbus_free(ctx); .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBmodbus_tcp_accept\fR(3) \fBmodbus_tcp_pi_accept\fR(3) \fBmodbus_tcp_pi_listen\fR(3) .SH "AUTHORS" .sp The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2> .SH "NOTES" .IP " 1." 4 stephane.raimbault@gmail.com .RS 4 \%mailto:stephane.raimbault@gmail.com .RE