- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to know when client socket is down ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 03:22 AM
01-08-2007 03:22 AM
I have tried 'select' for reading & writing to no avail. The server app thinks the socket is still up.
TIA
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 03:32 AM
01-08-2007 03:32 AM
Re: How to know when client socket is down ?
You can use netstat -an to determine the connection state, which will change to WAIT CLOSE state, then use ndd to close the connection.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 03:38 AM
01-08-2007 03:38 AM
Re: How to know when client socket is down ?
nettune (renamed in 11.0)
ndd
please have a look at:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=99069
Things to also investigate:
tcp_keepstart - If connection idle for x start sending requests
tcp_keepstop - length of time to keep sending requests
tcp_keepalive_interval
tcp_keepstart
tcp_ip_abort_interval
tcp_keepstop
tcp_ip_abort_cinterval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 05:48 AM
01-08-2007 05:48 AM
Re: How to know when client socket is down ?
Thanks again;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 09:33 AM
01-08-2007 09:33 AM
Re: How to know when client socket is down ?
In C, you want to use setsockopt() to set the SO_KEEPALIVE option on the socket.
In Perl, use the setsockopt() function as in C.
In Java, assuming java.net.Socket, use Socket.setSoTimeout() to set read timeouts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2007 03:46 AM
01-09-2007 03:46 AM
Re: How to know when client socket is down ?
Thanks again;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2007 05:30 AM
01-09-2007 05:30 AM
Re: How to know when client socket is down ?
TCP can only guess that the remote is down if it tries to send something to the remote and receives no response after some number of tries and/or length of time. If your server application is just sitting there receiving, then the TCP is not trying to send something to the remote and so will never know the remote is down.
The heartbeat mechanism could take one of two forms:
1) The server sends an "are you there" message to which the client responds.
2) The server expects to receive an "i am here message" every N units of time from the client.
In either case, if the response is not forthcoming within the limits your application desires your server code can decide to call close() against that socket.
The SO_KEEPALIVE path is a dodge - it will accomplish what you want, but you will have to live within the _system-wide_ keepalive settings - two different applications on the same server might have different needs, so an application-specific mechanism is always best.
Another option, rather than having the keepalive/heartbeat all the time on the socket, is to notice that you've received a new connection from a client IP for which you have an old connection (the remote IP and port are available to you in the accept() call). You could then send the "are you there" on the old connection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2007 10:08 PM
01-10-2007 10:08 PM
Re: How to know when client socket is down ?
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 01:29 AM
01-11-2007 01:29 AM
Re: How to know when client socket is down ?
I think your option - "notice that you've received a new connection from a client" - is a great idea. However, I am back to my original problem of not getting 'select' to work as expected in order to do it.
Is there something I'm missing etc, from the code snippets below? Select always returns 0, but netstat reports two established connections after I cycle the power on the client unit.
Thanks;
...
int listenfd;
fd_set readfds;
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
...
if ( (listenfd = socket(PF_INET,SOCK_STREAM, 0)) < 0) {
printf("sock error:");
...
}
...
/* bind,listen,accept, etc */
...
/* com loop taking place here */
...
FD_SET(listenfd, &readfds);
...
ret = select(listenfd, &readfds, NULL, NULL, &timeout);
if (ret > 0) {
printf("new connection ready!\n");
/* exit loop here */
}
else {
printf("select returns %d\n",ret);
...
}
/* end loop here */
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 04:50 AM
01-11-2007 04:50 AM
Re: How to know when client socket is down ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 09:03 AM
01-11-2007 09:03 AM
Re: How to know when client socket is down ?
ret = select(listenfd+1, &readfds, NULL, NULL, &timeout);
but still no luck...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 09:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 03:00 PM
01-11-2007 03:00 PM
Re: How to know when client socket is down ?
May be I don't understand the problem
completely, but if the remote host is shutdown by
an operator "nicely", the remote TCP/IP MUST
send a FIN and terminate the connection (which
means, you will NOT have connections in
ESTABLISHED state in the server hanging
around for days).
The only 2 conditions under which the server
shows the ESTABLISHED state for connections
whose peers are down would be (1) if the peer
machine crashed, or (2) the route between client
and server goes down. In both the cases, you
could write a separate heartbeat mechanism
(may be a script) that would just ping the client
system and kill all the local applications that you
want killed when the remote system is not
ping'able. This would be much easy to do than
modifying the source code.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2007 05:42 AM
01-12-2007 05:42 AM
Re: How to know when client socket is down ?
I could easily see someone just powering-down a scale.
Now...
It would be good to suggest to the scale manufacturer that they start thinking about a graceful shutdown of the device when someone hits the power switch. Afterall, their "scale" isn't just a scale any more, but a remote, weight-reporting computer :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2007 08:16 AM
01-12-2007 08:16 AM
Re: How to know when client socket is down ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2007 02:08 AM
01-14-2007 02:08 AM
Re: How to know when client socket is down ?
the peculiar situation here.
Thinking aloud, I can probably see a _potential_
solution involving IPFilter system firewall here,
though I have never tried this. IPFilter system
firewall on HP-UX provides a kernel tunable
"fr_tcpidletimeout" that can be set to as small
as 5 minutes. This will remove connections in
ESTABLISHED state that are idle for more than
5 minutes. Interesting point is, it would close
only those connections that are tracked by
IPFilter (i.e that has an IPFilter rule set). For all
other connections, the system wide timeout
value should work. So, potentially, you could
set specific IPFilter rules for IP addresses of the
scales that is creating the mess and set the
"fr_tcpidletimeout" to 5 minutes that will
be applied to only those connections.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2007 03:03 AM
01-19-2007 03:03 AM
Re: How to know when client socket is down ?
Rick,
great job - the tusc program was most helpful in troubleshooting!
Biswajit,
The IPFilter system firewall you describe is most interesting. While it doesn't solve my overall problem in this case, it is something worth studying for future needs...
Thanks again!