Here is some more information about the behaviour of
starts by looking-up the MAC-address of the target. If the IP-address has an entry in the ARP table, this happens very quickly. When an ARP look-up is needed, it will take at least half a second.
The number of attempts ( sending a
), and the time-outs between them are fixated in the library source code:
0.000 sec SYN-1
3.000 sec SYN-2
9.000 sec SYN-3
You can either
to a remote device in a blocking way, or by polling.
Blocking: the socket option
determines the maximum time that
will wait for a connection:
/* Wait at most 5 seconds. */
TickType_t xTimeout = pdMS_TO_TICKS( 5000ul );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xTimeout, sizeof( BaseType_t ) );
Mind that a useful value for
is either +/- 2, 5, or 11 seconds.
, a successful
will be notified as a
event. A successful acceptance of a new client triggers a
You can find complete examples of using
in the “protocols” directory ( FTP and HTTP server ).
When using “non-blocking” ways to connect, you can call this function to see if a connection was established:
/* returns pdTRUE if TCP socket is connected */
BaseType_t FreeRTOS_issocketconnected( Socket_t xSocket );
You may also call
the connection is established, to see any errors that might occurs.
If you do not want to block on
, and you don’t want to use
, there is a third way. Let your task block on a semaphore, and bind that semaphore to all sockets that it owns:
/* Define this in you FreeRTOSIPConfig.h */
define ipconfigSOCKETHASUSER_SEMAPHORE 1
/* Bind a semaphore to a socket. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SET_SEMAPHORE, ( void * ) &xMySemaphore, sizeof( xMySemaphore ) );
The semaphore will be given to for every event of interest: RX, TX, connect succeeded, acceptance of a client.
The same semaphore can be “bound” to many sockets of all types.
I attached a working “hello world” example of this method: “socketusing