/* Attempt to open the socket. */
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM, /*FREERTOS_SOCK_DGRAM for UDP.*/
FREERTOS_IPPROTO_UDP );
/* Check the socket was created. */
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
/* Bind to port 10000. */
xBindAddress.sin_port = FreeRTOS_htons( 10000 ); FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
for( ;; )
{ /* Receive data from the socket. ulFlags is zero, so the standard
interface is used. By default the block time is portMAX_DELAY, but it
can be changed using FreeRTOS_setsockopt(). */
lBytes = FreeRTOS_recvfrom( xListeningSocket,
cReceivedString,
sizeof( cReceivedString ),
0,
&xClient,
&xClientLength );
if( lBytes > 0 )
{ /* Data was received and can be process here. */
}
}
}
/* Attempt to open the socket. */
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET6, /* FREERTOS_AF_INET6 for IPv6 socket */
FREERTOS_SOCK_DGRAM, /*FREERTOS_SOCK_DGRAM for UDP.*/
FREERTOS_IPPROTO_UDP );
/* Check the socket was created. */
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
/* Bind to port 10000. */
xBindAddress.sin_port = FreeRTOS_htons( 10000 );
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
for( ;; )
{ /* Receive data from the socket. ulFlags is zero, so the standard
interface is used. By default the block time is portMAX_DELAY, but it
can be changed using FreeRTOS_setsockopt(). */
lBytes = FreeRTOS_recvfrom( xListeningSocket,
cReceivedString,
sizeof( cReceivedString ),
0,
&xClient,
&xClientLength );
if( lBytes > 0 )
{ /* Data was received and can be process here. */
}
}
}