Keep Alive not seen

Hi,
I’ve been trying to find some info on the KeepAlive facility in the Socket handling and think I have it set up but I seen no KA telegrams and when I try to retrieve the KA time after setting it, it seems to fail.

Is there a specific way I need to set it ?

I am using the following.

//open socket
----code------

//Set the NonBlocking option
setsockopt(fd, SOL_SOCKET, SO_NONBLOCK, &StateSet, sizeof StateSet);

//Set the KeepAlive option
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &StateSet, sizeof StateSet);

//Set the KeepAlive time
unsigned short keepalivetime = 10;
//Need to link to external settings here for keep alive time.
NAIpSetKaInterval(keepalivetime);

//Allow to check the set Keep Alive time
unsigned short CurrentkeepAlive = NAIpGetKaInterval();

If I am doing anything wrong I would understand that the result would be incorrect, but from what I can see the code is correct.

Hope you can help.

Marc