View topic - TCPIP 4.25 - SO_KEEPALIVE

TCPIP 4.25 - SO_KEEPALIVE

For the old QNX2 and QNX4 RTOS

TCPIP 4.25 - SO_KEEPALIVE

Postby johnny » Mon Jun 23, 2008 8:54 pm

The default is set to 2 hours. How do you change it?

We have an application that handle mutiple TCP clients. If the client get reseted the server don't get notify. I'm trying to setup a hearbeat message to close the inactive socket. 2 hours is kinda too long , i'm looking for something like 30 sec heartbeat.

Any info will be appreciated

Thanks
johnny
Active Member
 
Posts: 70
Joined: Thu May 06, 2004 8:24 pm

RE: TCPIP 4.25 - SO_KEEPALIVE

Postby mario » Mon Jun 23, 2008 8:57 pm

You have to do it at the application level, playing with SO_KEEPALIVE is not the way to do this.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: TCPIP 4.25 - SO_KEEPALIVE

Postby johnny » Mon Jun 23, 2008 9:10 pm

So what are you recommending? Read socket and if no data for 30 sec then close it? Any better way?
johnny
Active Member
 
Posts: 70
Joined: Thu May 06, 2004 8:24 pm

RE: TCPIP 4.25 - SO_KEEPALIVE

Postby mario » Tue Jun 24, 2008 4:01 am

The best is to have the hearbeat data go in both direction. The server and client send data to each other every x seconds, what ever you need to comply with the requirement. That way server can detect if client is dead and client can detect if server is dead.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Can't implement heartbeat

Postby johnny » Tue Jun 24, 2008 1:34 pm

Mario,
Infortunatly most of the client doesn't support heartbeat message.
I have to stick with what I have.

I will keep track of every socket and if no data for 5 min then I will close it.
johnny
Active Member
 
Posts: 70
Joined: Thu May 06, 2004 8:24 pm

RE: Can

Postby xtang » Tue Jun 24, 2008 2:16 pm

I think the TCP_KEEPALIVE option also exist in 4.25 TCPIP (can't say for sure which version of TCPIP though).

You create a socket(), set the SO_KEEPALIVE on the socket (if you are accepting, make sure you do this on the accept socket, not the listen one). And you can also set the TCP_KEEPALIVE on the socket, to set the idle time.

Note you can change that 2 hours to any seconds you want, but once connection failed, it still took TCP about 10 minutes to decide and close the connection.
xtang
QNX Master
 
Posts: 313
Joined: Thu Jul 18, 2002 5:01 pm

RE: Can

Postby mario » Tue Jun 24, 2008 3:45 pm

From memory the KEEPALIVE option is there but you can only set it to on or off, no control over its timings.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby johnny » Wed Jun 25, 2008 2:48 pm

So I'm gonna stick with my implementation. If the client want keep their connection alive then they will need to send at least 1 caractere before the timeout expired.
johnny
Active Member
 
Posts: 70
Joined: Thu May 06, 2004 8:24 pm

Postby Tim » Wed Jun 25, 2008 5:00 pm

Johnny,

Typically what I do on the server side of things is to set a max number of clients I expect to handle (say 10).

As each client connects and sends messages I timestamp them (the connection time and each message received time).

When all 10 connections are filled, on the 11th connection request I go through my list of 10 connections and close the oldest one (presumably it's a dead one). Also, if you only expect 1 connection per client, you can easily check and see if the IP of the incoming connection matches any in your currently connected list. If it does, you can close the old one (that's dead) and accept the new one into it's place.

Then you don't have to rely on clients sending keep alives.

Tim
Tim
Senior Member
 
Posts: 1444
Joined: Wed Mar 10, 2004 12:28 am

Postby johnny » Thu Jun 26, 2008 3:46 pm

Tim,
Thanks for sharing your implementation. Actually i'm using a counter for each socket and when it reach the max then I close it.

But the one thing I didn't really figure is how to limit the number of socket. For our application we may have between 20-100 sockets which is variable depending of the sites.

I tried to set listen to 0 instead of 5 to stop our socket to listen for connection if reach max (100) but it doesn't work. Client still get queue and they don't receive a message like connection refused.

I have also try the function shutdown but I can't restart my socket to listen.

So that could be a nub question but how do you stop your socket to listen temporaly?

May be I'm missing something but the following didn't work for me
2 sockets left = Listen(2)
0 sockets left = Listen(0)
johnny
Active Member
 
Posts: 70
Joined: Thu May 06, 2004 8:24 pm

Postby mezek » Thu Jun 26, 2008 6:09 pm

the connection negotiation is done using several packets
the listen(N) limits the number of concurrent connection negotiations

to limit maximum number of connections do
s=accept();
if (current_connections > max_connections)
close(s);
mezek
Senior Member
 
Posts: 193
Joined: Wed Mar 03, 2004 5:51 pm


Return to QNX2 and QNX4

Who is online

Users browsing this forum: No registered users and 7 guests

cron