Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more
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
- 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: - [SOCK_STREAM](SOCK_STREAM)
- [SOCK_DGRAM](SOCK_DGRAM)
[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.
- 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
TCP example
SSL example
Generated on Wed Jul 13 2022 16:32:38 by
1.7.2