Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Embed: (wiki syntax)

« Back to documentation index

socket

socket
[Function]

Synchronous socket allocation function based on the specified socket type. More...

Functions

NMI_API SOCKET socket (uint16 u16Domain, uint8 u8Type, uint8 u8Flags)

Detailed Description

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.


Function Documentation

NMI_API SOCKET socket ( uint16  u16Domain,
uint8  u8Type,
uint8  u8Flags 
)
Parameters:
[in]u16DomainSocket family. The only allowed value is AF_INET (IPv4.0) for TCP/UDP sockets.
[in]u8TypeSocket type. Allowed values are:

  • [SOCK_STREAM](SOCK_STREAM)
  • [SOCK_DGRAM](SOCK_DGRAM)
[in]u8FlagsUsed to specify the socket creation flags. It shall be set to zero for normal TCP/UDP sockets. It could be SOCKET_FLAGS_SSL if the socket is used for SSL session. The use of the flag SOCKET_FLAGS_SSL has no meaning in case of UDP sockets.
Precondition:
The socketInit function must be called once at the beginning of the application to initialize the socket handler. before any call to the socket function can be made.
See also:
connect bind listen accept recv recvfrom send sendto close setsockopt getsockopt
Returns:
On successful socket creation, a non-blocking socket type is created and a socket ID is returned In case of failure the function returns a negative value, identifying one of the socket error codes defined. For example: SOCK_ERR_INVALID for invalid argument or SOCK_ERR_MAX_TCP_SOCK if the number of TCP allocated sockets exceeds the number of available sockets.
Remarks:
The socket function must be called a priori to any other related socket functions "e.g. send, recv, close ..etc"

Example

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

    SOCKET UdpServerSocket = -1;
    
    UdpServerSocket = socket (AF_INET, SOCK_DGRAM, 0);

TCP example

    static SOCKET tcp_client_socket = -1;

    tcp_client_socket = socket (AF_INET, SOCK_STREAM, 0));

SSL example

static SOCKET ssl_socket = -1;

ssl_socket = socket (AF_INET, SOCK_STREAM, SOCK_FLAGS_SSL));