After successful socket binding to an IP address and port on the system, start listening on a passive socket for incoming connections.
The socket must be bound on a local port or the listen operation fails. Upon the call to the asynchronous listen function, response is received through the event SOCKET_MSG_LISTEN in the socket callback. A successful listen means the TCP server operation is active. If a connection is accepted, then the application socket callback function is notified with the new connected socket through the event SOCKET_MSG_ACCEPT. Hence there is no need to call the accept function after calling listen.
After a connection is accepted, the user is then required to call recv to receive any packets transmitted by the remote host or to receive notification of socket connection termination.
Functions | |
NMI_API sint8 | listen (SOCKET sock, uint8 backlog) |
After successfully binding a socket to an IP address and port on the system, start listening passively for incoming connections. The socket must be bound on a local port or the listen operation fails. Upon the call to the asynchronous listen function, response is received through the event @ref SOCKET_MSG_LISTEN in the socket callback. A successful listen means the TCP server operation is active. If a connection is accepted, then the application socket callback function is notified with the new connected socket through the event @ref SOCKET_MSG_ACCEPT. Hence there is no need to call the @ref accept function after calling @ref listen. After a connection is accepted, the user is then required to call @ref recv to receive any packets transmitted by the remote host or to receive notification of socket connection termination.
[in] | sock | Socket ID, must hold a non negative value. A negative value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. |
[in] | backlog | Not used by the current implementation. |
This example demonstrates the call of the listen socket operation after a successful socket operation.
[in] | sock | Socket ID, must hold a non negative value. A negative value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. |
[in] | backlog | Not used by the current implementation. |
This example demonstrates the call of the listen socket operation after a successful socket operation.
References MAX_SOCKET, NULL, tstrListenCmd::sock, SOCK_ERR_INVALID, SOCK_ERR_INVALID_ARG, SOCK_ERR_NO_ERROR, SOCKET_CMD_LISTEN, SOCKET_REQUEST, tstrSocket::u16SessionID, tstrListenCmd::u16SessionID, and tstrListenCmd::u8BackLog.
Referenced by IperfTCP_ServerStart(), and prov_socket_cb().