 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Allan Bruce Guest
|
Posted: Thu Jul 21, 2005 11:43 am Post subject: socket connection not being reset correctly |
|
|
I have an instant messenger server written in Java and running on linux. If
the connection between the client (C++ win32) gets broken for any reason
(e.g. network cable pulled) then the server doesn't notice and still thinks
the connection is intact. Whats more, we send out data on the connection
every 60 seconds to 'test' the connection, but the server is still not
detecting an error in the connection. At least I would have thought that
trying to send out data on a broken connection would cause it to fail.
I used to run the server on windows and I'm pretty sure that this behaviour
was not apparent then. Are there any known issues of this on linux? or am I
doing something wrong with my code (below)?
Thanks,
Allan
lreader = new BufferedReader(new SocketInputStream(lCCB.getSocket));
try
{
String lread = lreader.readLine();
if (lread == null)
{
throw new Exception("Graceful client disconnect");
}
}
catch (Exception e)
{
dosconnectedCLient(lCCB);
}
|
|
| Back to top |
|
 |
Alan Krueger Guest
|
Posted: Fri Jul 22, 2005 4:07 am Post subject: Re: socket connection not being reset correctly |
|
|
Allan Bruce wrote:
| Quote: | lreader = new BufferedReader(new SocketInputStream(lCCB.getSocket));
|
I suspect this isn't the actual code, unless you have a field called
"getSocket", which would be mighty peculiar.
| Quote: | try
{
String lread = lreader.readLine();
if (lread == null)
{
throw new Exception("Graceful client disconnect");
}
}
catch (Exception e)
{
dosconnectedCLient(lCCB);
}
|
*blink*
|
|
| Back to top |
|
 |
Allan Bruce Guest
|
Posted: Fri Jul 22, 2005 8:05 am Post subject: Re: socket connection not being reset correctly |
|
|
"Alan Krueger" <wgzkid502 (AT) sneakemail (DOT) com> wrote
| Quote: | Allan Bruce wrote:
lreader = new BufferedReader(new SocketInputStream(lCCB.getSocket));
I suspect this isn't the actual code, unless you have a field called
"getSocket", which would be mighty peculiar.
|
I have a lot of debug info and logging so I copied over the necessary bits,
and in doing so, I forgot to add the () of getSocket. ANd the typo below,
dosconnceted ;-)
| Quote: | try
{
String lread = lreader.readLine();
if (lread == null)
{
throw new Exception("Graceful client disconnect");
}
}
catch (Exception e)
{
dosconnectedCLient(lCCB);
}
*blink*
|
I have found that netstat reckons the connections are still up, so is it my
JVM thats causing the problem? Or can I setup the sockets in a way for them
to not display this behaviour?
Thanks.
Allan
|
|
| Back to top |
|
 |
Gordon Beaton Guest
|
Posted: Fri Jul 22, 2005 8:29 am Post subject: Re: socket connection not being reset correctly |
|
|
On Fri, 22 Jul 2005 09:05:57 +0100, Allan Bruce wrote:
| Quote: | I have found that netstat reckons the connections are still up, so
is it my JVM thats causing the problem? Or can I setup the sockets
in a way for them to not display this behaviour?
|
Unplugging a cable should not normally cause a socket connection to
terminate, and this has absolutely nothing to do with Java. TCP was
designed to be resilient and will handle intermittent network
interruptions. Consider also how your computer should detect an
unplugged cable somewhere else along your communication route, not
directly attached to either of your computers.
If your application really needs to detect this situation, you should
add something like a heartbeat message to your protocol. If you don't
get a response within a certain timeout, assume the network is down.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
|
| Back to top |
|
 |
Allan Bruce Guest
|
Posted: Fri Jul 22, 2005 8:53 am Post subject: Re: socket connection not being reset correctly |
|
|
"Gordon Beaton" <not (AT) for (DOT) email> wrote
| Quote: | On Fri, 22 Jul 2005 09:05:57 +0100, Allan Bruce wrote:
I have found that netstat reckons the connections are still up, so
is it my JVM thats causing the problem? Or can I setup the sockets
in a way for them to not display this behaviour?
Unplugging a cable should not normally cause a socket connection to
terminate, and this has absolutely nothing to do with Java. TCP was
designed to be resilient and will handle intermittent network
interruptions. Consider also how your computer should detect an
unplugged cable somewhere else along your communication route, not
directly attached to either of your computers.
If your application really needs to detect this situation, you should
add something like a heartbeat message to your protocol. If you don't
get a response within a certain timeout, assume the network is down.
/gordon
|
We do have this implemented however windows does have this behaviour, when
it tries to send something on a broken connection it causes an error and the
socket can then be closed. This was the case when Java was running on the
windows box, but now on Linux the behaviour is different. Perhaps I should
direct my question to a linux group? But I thought it could be something to
do with the JVM options or there may be a way to setup sockets to the way I
want.
Allan
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|