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.
- 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] | u8Config | Used to specify the socket configuration. The following configuration values are defined:
|
- 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 secure 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.
Allocation 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
static SOCKET tcp_client_socket = -1;
SSL example
static SOCKET ssl_socket = -1;
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.
- 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] | u8Config | Used to specify the socket configuration. The interpretation of this parameter depends on the setting of u8Type.
- When u8Type is SOCK_STREAM the following configuration values are defined:
- When u8Type is SOCK_RAW, the following configuration values are defined:
- For all values of u8Type, the following configuration values are defined:
- SOCKET_CONFIG_DEFAULT: The default configuration.
All other configuration values are reserved and should not be used.
|
- 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 secure 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.
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
static SOCKET tcp_client_socket = -1;