TCP KEEPALIVE Query

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TCP KEEPALIVE Query

Jump to solution
1,186 Views
mohwaqas12
Contributor III

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

Labels (1)
Tags (3)
1 Solution
698 Views
Martin_
NXP Employee
NXP Employee

keepalive time seems to be in minutes, not miliseconds.

View solution in original post

2 Replies
699 Views
Martin_
NXP Employee
NXP Employee

keepalive time seems to be in minutes, not miliseconds.

698 Views
mohwaqas12
Contributor III

Thank you Martin, I dont know , why i had been trying to set keepalive in miliseconds. It turns out to be in minutes . Thank you

0 Kudos