I made a TCP/IP server on my microcontroller based on the following link:
Which works properly.
Now what I need is to determine the IP address of the client that connected and then ping that address.
To obtain the client’s address, I do the following:
apptcpipserverData.xConnectedSocket = FreeRTOS_accept(apptcpipserverData.xListeningSocket, &apptcpipserverData.xClient, &xSize );
configASSERT( apptcpipserverData.xConnectedSocket != FREERTOS_INVALID_SOCKET );
/** clientAddress is struct freertos_sockaddr *clientAddress, and clientAddress->sin_addr will be set to the IP address of the remote connected socket**/
if (-pdFREERTOS_ERRNO_EINVAL != FreeRTOS_GetRemoteAddress(apptcpipserverData.xConnectedSocket, clientAddress ))
{
apptcpipserverData.state = APPTCPIPSERVER_STATE_RECEIVE_DATA_FROM_CLIENT;
}
else
{
FreeRTOS_shutdown(apptcpipserverData.xConnectedSocket, FREERTOS_SHUT_RDWR );
apptcpipserverData.state = APPTCPIPSERVER_STATE_TRY_CLOSE_SCOKET
}
To ping the client I do the following:
usRequestSequenceNumber = FreeRTOS_SendPingRequest( clientAddress.sin_addr, 8, 100 / portTICK_PERIOD_MS );
if( usRequestSequenceNumber == pdFAIL )
{
/* The ping could not be sent because a network buffer could not be
obtained within 100ms of FreeRTOS_SendPingRequest() being called. */
}
else
{
if( xQueueReceive( xPingReplyQueue,&usReplySequenceNumber,200 / portTICK_PERIOD_MS ) == pdPASS )
{
/* A ping reply was received. Was it a reply to the ping just sent? */
if( usRequestSequenceNumber == usReplySequenceNumber )
{
/* This was a reply to the request just sent. */
}
else
{
}
}
}
but when compiling, the compiler tells me the following error:
I think you should use an object resp. a struct freertos_sockaddr clientAddress; and provide it’s address to FreeRTOS_GetRemoteAddress( …, &clientAddress );
to get it filled with the peer address.
Also then you can correctly use clientAddress.sin_addr to ping.
[quote]build/default/production/_ext/1360937237/apptcpipserver.o: In function APPTCPIPSERVER_Tasks': c:/projects/alexa home 7/firmware/src/apptcpipserver.c:249: undefined reference to FreeRTOS_SendPingRequest’[/quote]
Hmm … this are completely unrelated issues. With the fix using an object the 2nd error is clear, right ? It’s just syntactically wrong using the-> operator.
Regarding 1st issue is it possible that your project doesn’t contain the respective source file where FreeRTOS_SendPingRequest is defined or that it doesn’t get compiled/linked in properly ?
The TCPIP server works great, the reason I want to ping the client is that a client termination can happen without closing the socket.
The server (the microcontroller) doesn’t detect this event, and when the client wants to reconnect, it is not possible because it only allows a single client to connect and the socket has not been closed.
That is why I want to ping the client and if the MCU detects that after a certain time there is no response, the server would close the socket.
If there is a better idea regarding that problem, I might just drop the idea of pinging.