AnsweredAssumed Answered

TCP KEEPALIVE Query

Question asked by Muhammad Waqas Athar on Nov 28, 2012
Latest reply on Dec 3, 2012 by Muhammad Waqas Athar

Hello mqx users,

 

I have setup a client client socket using mqx 3.7 , to transfer data to server whenever it finds something on SD Card

I want to use KEEPALIVE feature , to let my task know that connection has been lost/reset , if it hasn't sent anything in some time , but unfortunately KEEPALIVE does not work at all.

 

The Algorithm is like this :

  • Create a Socket
  • Set KEEPALIVE Socket option // KEEP ALIVE is set to 5000 i.e 5 seconds
  • Call Connect  // to connect to server
  • Loop Until some error occurs on socket
    • Send some data // send data only if present
    • Time Delay (5000) // put task to sleep for 5 Seconds using _time_delay(5000);\
    • Check Socket State // using ioctl  OPT_SOCKET_ERROR
    • Break out of loop ( if error occurs and keep connecting until socket is connected )

 

I run this task and the socket connects to server , but it does not send KEEPALIVE Probes , i am capturing packets on wireshark and i only see connection establishment packets not the keep alive .

 

I have some queries :

  1. Does KEEPALIVE works when we use active sockets?
  2. Does KEEPALIVE has some specific requirements in mqx to make it work, like minimum time after which keepalive probes are sent.
  3. Does polling socket state using ioctl OPT_SOCKET_ERROR works?. i e Does it returns state if it detects some error . like Shutdown from server, connection lost etc.

 

Please correct me , i might be missing some important steps to make socket options work.

 

Regards

Outcomes