FreeRTOS_sockets.h
Socket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol );
Create a TCP or UDP socket.
See the FreeRTOS-Plus-TCP networking tutorial
for more information on using both TCP and UDP sockets.
Parameters:
xDomain
|
Set to FREERTOS_AF_INET to create a socket that uses the IPv4 address family.
Set to FREERTOS_AF_INET6 to create a socket that uses the IPv6 address family.
No other values are valid.
|
xType
|
Set to FREERTOS_SOCK_STREAM to create a TCP socket.
Set to FREERTOS_SOCK_DGRAM to create a UDP socket.
No other values are valid.
|
xProtocol
|
Set to FREERTOS_IPPROTO_TCP to create a TCP socket.
Set to FREERTOS_IPPROTO_UDP to create a UDP socket.
No other values are valid.
|
Returns:
If a socket is created successfully, then the socket handle is returned. If
there is insufficient FreeRTOS heap memory available for the socket to be
created then FREERTOS_INVALID_SOCKET is returned.
Example usage:
The following code snippets show how to create a UDP and TCP socket
respectively.
#include "FreeRTOS_sockets.h"
void aFunction( void )
{
Socket_t xSocket;
struct freertos_sockaddr xBindAddress;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
xBindAddress.sin_port = FreeRTOS_htons( 9999 );
if( FreeRTOS_bind( xSocket, &xBindAddress, sizeof( &xBindAddress ) ) == 0 )
{
}
}
else
{
}
}
Example use of the FreeRTOS_socket() API function to create a UDP socket
#include "FreeRTOS_sockets.h"
void aFunction( void )
{
Socket_t xSocket;
struct freertos_sockaddr xBindAddress;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET,
FREERTOS_SOCK_STREAM,
FREERTOS_IPPROTO_TCP );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
}
else
{
}
}
Example use of the FreeRTOS_socket() API function to create a TCP socket
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.