[ ]
 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS Labs FreeRTOS+TCP FreeRTOS+FAT Contact / Enquiries


FreeRTOS+TCP is still in the lab
FreeRTOS+TCP is already used in commercial products and we encourage you to try it yourself. Be aware however that we are still refining its design, and the source code and documentation do not yet meet Real Time Engineers Ltd's strict quality standards.
Please use the forum for support, feedback and ideas, or contact us directly if you have a specific business interest.

FreeRTOS_socket()

[FreeRTOS+TCP API Reference]

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+TCP networking tutorial for more information on using both TCP and UDP sockets.

Parameters:

xDomain   Must be set to FREERTOS_AF_INET.

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.


/* FreeRTOS+TCP sockets include. */
#define "FreeRTOS_sockets.h"

void aFunction( void )
{
/* Variable to hold the created socket. */
Socket_t xSocket;
struct freertos_sockaddr xBindAddress;

    /* Create a UDP socket. */
    xSocket = FreeRTOS_socket( FREERTOS_AF_INET,
                               FREERTOS_SOCK_DGRAM,
                               FREERTOS_IPPROTO_UDP );

    /* Check the socket was created successfully. */
    if( xSocket != FREERTOS_INVALID_SOCKET )
    {
        /* The socket was created successfully and can now be used to send data
        using the FreeRTOS_sendto() API function.  Sending to a socket that has
        not first been bound will result in the socket being automatically bound
        to a port number.  Use FreeRTOS_bind() to bind the socket to a
        specific port number.  This example binds the socket to port 9999.  The
        port number is specified in network byte order, so FreeRTOS_htons() is
        used. */
        xBindAddress.sin_port = FreeRTOS_htons( 9999 );
        if( FreeRTOS_bind( xSocket, &xBindAddress, sizeof( &xBindAddress ) ) == 0 )
        {
            /* The bind was successful. */
        }
    }
    else
    {
        /* There was insufficient FreeRTOS heap memory available for the socket
        to be created. */
    }
}

						
Example use of the FreeRTOS_socket() API function to create a UDP socket



/* FreeRTOS+TCP sockets include. */
#define "FreeRTOS_sockets.h"

void aFunction( void )
{
/* Variable to hold the created socket. */
Socket_t xSocket;
struct freertos_sockaddr xBindAddress;

    /* Create a TCP socket. */
    xSocket = FreeRTOS_socket( FREERTOS_AF_INET,
                               FREERTOS_SOCK_STREAM,
                               FREERTOS_IPPROTO_TCP );

    /* Check the socket was created successfully. */
    if( xSocket != FREERTOS_INVALID_SOCKET )
    {
        /* The socket was created successfully and can now be used to connect to
        a remote socket using FreeRTOS_connect(), before sending data using
        FreeRTOS_send().  Alternatively the socket can be bound to a port using
        FreeRTOS_bind(), before listening for incoming connections using
        FreeRTOS_listen(). */
    }
    else
    {
        /* There was insufficient FreeRTOS heap memory available for the socket
        to be created. */
    }
}

						
Example use of the FreeRTOS_socket() API function to create a TCP socket


[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS Labs Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.