Synchronous socket allocation function based on the specified socket type.
Created sockets are non-blocking and their possible types are either TCP or a UDP sockets. The maximum allowed number of TCP sockets is TCP_SOCK_MAX sockets while the maximum number of UDP sockets that can be created simultaneously is UDP_SOCK_MAX sockets.
Functions | |
NMI_API SOCKET | socket (uint16 u16Domain, uint8 u8Type, uint8 u8Config) |
[in] | u16Domain | Socket family. The only allowed value is AF_INET (IPv4.0) for TCP/UDP sockets. |
[in] | u8Type | Socket type. Allowed values are: |
[in] | u8Config | Used to specify the socket configuration. The following configuration values are defined:
|
This example demonstrates the use of the socket function to allocate the socket, returning the socket handler to be used for other socket operations. Socket creation is dependent on the socket type.
UDP example
TCP example
SSL example
References AF_INET, tstrSocket::bIsUsed, gu16SessionID, M2M_INFO, m2m_memset(), SOCK_DGRAM, SOCK_STREAM, SOCKET_CMD_SSL_CREATE, SOCKET_CONFIG_SSL_DELAY, SOCKET_CONFIG_SSL_OFF, SOCKET_REQUEST, SSL_FLAGS_ACTIVE, SSL_FLAGS_DELAY, SSL_FLAGS_NO_TX_COPY, tstrSSLSocketCreateCmd::sslSock, TCP_SOCK_MAX, tstrSocket::u16SessionID, tstrSocket::u8SSLFlags, and UDP_SOCK_MAX.
Referenced by connect_cmd_handler(), ConnectNetwork(), http_client_send_request(), main(), NMI_GrowlSendNotification(), smtpConnect(), sslConnect(), and wifi_ap_provision().