Establishes a TCP connection with a remote server.
The asynchronous connect function must be called after receiving a valid socket ID from the socket function. The application socket callback function is notified of the result of the connection attempt through the event SOCKET_MSG_CONNECT, along with a structure tstrSocketConnectMsg. If socket connection fails, the application should call close(). A successful connect means the TCP session is active. The application is then required to make a call to the recv to receive any packets transmitted by the remote server, unless the application is interrupted by a notification of socket connection termination.
Functions | |
NMI_API sint8 | connect (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen) |
[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] | pstrAddr | Address of the remote server. |
[in] | pstrAddr | Pointer to socket address structure sockaddr_in. |
[in] | u8AddrLen | Size of the given socket address structure in bytes. Not currently used, implemented for BSD compatibility only. |
The example demonstrates a TCP application, showing how the asynchronous call to the connect function is made through the main function and how the callback function handles the SOCKET_MSG_CONNECT event.
Main Function
Socket Callback
References m2m_memcpy(), MAX_SOCKET, NULL, tstrConnectCmd::sock, SOCK_ERR_INVALID, SOCK_ERR_INVALID_ARG, SOCK_ERR_NO_ERROR, SOCKET_CMD_CONNECT, SOCKET_CMD_SSL_CONNECT, SOCKET_REQUEST, SSL_FLAGS_ACTIVE, tstrConnectCmd::strAddr, tstrSocket::u16SessionID, tstrConnectCmd::u16SessionID, tstrSocket::u8SSLFlags, and tstrConnectCmd::u8SslFlags.
Referenced by ConnectNetwork().