473,388 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to tell if the other end of socket connection is dead without polling?

Hi,

I have a Java application which runs a server socket on a PC. Various
sensors (using microprocessors) can call it up and each gets its own thread
running the socket connection.

The sensors send in data at random times. This all works OK.

Sometimes one of the sensors fails or goes off-line. How can I tell from
the server end? If they fail I would like to close the link down.

Obviously I could poll links on a periodic basis and mark the link as dead
after a specified timeout but this seems rather inelegant. If I chose a
short period the network might be very busy for a short time and cause a
false timeout. If the period is long then I either have to start a new
thread to handle the polling or elselive with my main application blocking.
Anyway, there might be several hundred sensors and I don't want to clutter
the network up with polling packets. Is there a better way?

I would be grateful for any help.

Regards,

Nick
Aug 25 '08 #1
2 4242
Nick Toop wrote:
Hi,

I have a Java application which runs a server socket on a PC. Various
sensors (using microprocessors) can call it up and each gets its own thread
running the socket connection.

The sensors send in data at random times. This all works OK.

Sometimes one of the sensors fails or goes off-line. How can I tell from
the server end? If they fail I would like to close the link down.

Obviously I could poll links on a periodic basis and mark the link as dead
after a specified timeout but this seems rather inelegant. If I chose a
short period the network might be very busy for a short time and cause a
false timeout. If the period is long then I either have to start a new
thread to handle the polling or elselive with my main application blocking.
Anyway, there might be several hundred sensors and I don't want to clutter
the network up with polling packets. Is there a better way?

I would be grateful for any help.

Regards,

Nick

If you don't send data on a TCP stream, nothing is sent. There is no
detection of crashes built into the TCP protocol, so you will have to
implement this yourself.

On the client side I usually mark the time of the last packet sent and
use that for determining when a keepalive packet needs to be sent
meaning that if the application itself sends and receives data regularly
no keepalive packets needs to be sent at all. Only when the stream is
idle will I send keepalives.

On the server side I mark the time of the last received packet from each
client and have a timer to check the clients. If the server hasn't heard
from the clients in a configurable amount of time the stream is shut down.
Aug 27 '08 #2
On Wed, 27 Aug 2008 13:01:42 +0200, Robert Larsen wrote:
Nick Toop wrote:
>Hi,

I have a Java application which runs a server socket on a PC. Various
sensors (using microprocessors) can call it up and each gets its own
thread running the socket connection.

The sensors send in data at random times. This all works OK.

Sometimes one of the sensors fails or goes off-line. How can I tell
from the server end? If they fail I would like to close the link down.

Obviously I could poll links on a periodic basis and mark the link as
dead after a specified timeout but this seems rather inelegant. If I
chose a short period the network might be very busy for a short time
and cause a false timeout. If the period is long then I either have to
start a new thread to handle the polling or elselive with my main
application blocking. Anyway, there might be several hundred sensors
and I don't want to clutter the network up with polling packets. Is
there a better way?

I would be grateful for any help.

Regards,

Nick

If you don't send data on a TCP stream, nothing is sent. There is no
detection of crashes built into the TCP protocol, so you will have to
implement this yourself.
http://www.developerweb.net/forum/showthread.php?t=2983

Sep 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joe | last post by:
Hi, I browsed the news and a few seem to have this problem too, but no solution ! I have a client server application where in case the connection gets bad (crashes or whatever) client or...
4
by: Frank Meng | last post by:
Hi. I am trying a csharp sample from http://www.codeproject.com/csharp/socketsincs.asp . (Sorry I didn't post all the source codes here, please get the codes from above link if you want to try)....
7
by: | last post by:
Hi all, I have a simple .aspx page running on net 2.0 that is trying to do a http post to a remote server. Here is the code Private Function ProcessRequests(ByVal strbody As String) As String...
2
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
4
by: Droopy | last post by:
Hi, I wrote a program that runs on about 20 machines. Each machine is connected with a socket on all other machines. Each socket has its own handling thread. The main reading loop is using Poll...
6
by: Abubakar | last post by:
Hi, lets say I have a connected SOCKET s. At some point in time, I want to know if the "s" is still valid, that it is still connected. Is there any API that I can give me this information? And...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
1
by: jm.carp | last post by:
I'm writing a tcp client that grabs data from a server at 32hz. But the connection drops exactly one minute after it's opened. I can get data from the server fine for the first 60s, and then the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.