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) |
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 @ref TCP_SOCK_MAX sockets while the maximum number of UDP sockets that can be created simultaneously is @ref UDP_SOCK_MAX sockets.
[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 interpretation of this parameter depends on the setting of u8Type.
|
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.
[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(), RAW_SOCK_ID, SOCK_DGRAM, SOCK_RAW, SOCK_STREAM, SOCKET_CMD_SSL_CREATE, SOCKET_CONFIG_IPPROTO_RAW, 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(), connect_to_server(), ConnectNetwork(), demo_start(), handle_start_connect(), http_client_send_request(), iot_tls_connect(), IperfTCP_ClientStart(), IperfTCP_ServerStart(), IperfUDP_ClientStart(), IperfUDP_ServerStart(), main(), NMI_GrowlSendNotification(), run_udp_client(), run_udp_server(), setup_android_sockets(), smtpConnect(), sslConnect(), and wifi_ap_provision().