![]() |
WINC1500 IoT Software APIs
19.5.2
WINC Software API Reference Manual
|
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
◆ socket()
- Parameters
-
[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] u8Flags Used 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.
- 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;
TCP example
static SOCKET tcp_client_socket = -1;
SSL example
static SOCKET ssl_socket = -1;
Generated on Thu Jan 26 2017 22:15:21 for WINC1500 IoT Software APIs by
