Name

netconn_accept() — Wait for incoming connections

Synopsis

err_t netconn_accept (struct netconn *conn , struct netconn **new_conn );

Description

This function blocks the process until a connection request from a remote host arrives on the TCP connection conn. The connection must be in the LISTEN state so netconn_listen() must be called prior to netconn_accept(). When a connection is established with the remote host, a new connection structure is returned in the new_conn parameter.

Example

Example 156.5. This example shows how to open a TCP server on port 2000 [*]

int
main()
{
    struct netconn *conn, *newconn;

    /* create a connection structure */
    conn = netconn_new(NETCONN_TCP);

    /* bind the connection to port 2000 on any local IP address */
    netconn_bind(conn, NULL, 2000);

    /* tell the connection to listen for incoming connection requests */
    netconn_listen(conn);

    /* block until we get an incoming connection */
    if (netconn_accept(conn, newconn) == ERR_OK) {
        /* do something with the connection */
        process_connection(newconn);

        /* deallocate both connections */
        netconn_delete(newconn);
    }
    netconn_delete(conn);
}



[*] This is only an example for illustrative purposes, and a complete version should perform comprehensive error checking.