Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Recognizing when a Socket connection goes away.

Reply
Thread Tools

Recognizing when a Socket connection goes away.

 
 
Steve.
Guest
Posts: n/a
 
      02-02-2004
I'm a C++ programmer trying to get up to speed in Java and possibly
save my career. I'm doing some socket programming, basically a
java client on a windows machine talking to a C++ server on a Solaris
machine. I managed to kludge things around and get them talking to
each other using DataInputStream and DataOutputStream. The thing I
can't figure out now is how to get the Java client to recognize when
the server connection ends. I tried catching IOException, but that
doesn't seem to help. Also I tried calling and checking
getRemoteServerAddress before accessing the Socket.

Any ideas of a good way to sense a connection loss?
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      02-02-2004
On 2 Feb 2004 07:55:21 -0800, Steve. wrote:
> I'm a C++ programmer trying to get up to speed in Java and possibly
> save my career. I'm doing some socket programming, basically a
> java client on a windows machine talking to a C++ server on a
> Solaris machine. I managed to kludge things around and get them
> talking to each other using DataInputStream and DataOutputStream.
> The thing I can't figure out now is how to get the Java client to
> recognize when the server connection ends. I tried catching
> IOException, but that doesn't seem to help. Also I tried calling and
> checking getRemoteServerAddress before accessing the Socket.
>
> Any ideas of a good way to sense a connection loss?


The only way to detect EOF is to read from the DataInputStream or
write to the DataOutputStream. The various read() and write() methods
all have ways of indicating EOF, see the API documentation for
details.

/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
 
Reply With Quote
 
 
 
 
Tony Morris
Guest
Posts: n/a
 
      02-04-2004
"Steve." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> I'm a C++ programmer trying to get up to speed in Java and possibly
> save my career. I'm doing some socket programming, basically a
> java client on a windows machine talking to a C++ server on a Solaris
> machine. I managed to kludge things around and get them talking to
> each other using DataInputStream and DataOutputStream. The thing I
> can't figure out now is how to get the Java client to recognize when
> the server connection ends. I tried catching IOException, but that
> doesn't seem to help. Also I tried calling and checking
> getRemoteServerAddress before accessing the Socket.
>
> Any ideas of a good way to sense a connection loss?


The nature of TCP (not Java) is such that neither end can determine if the
other has closed until a read/write operation occurs. Many applications get
around this by sending a ping/pong request/response at intervals.

If the ping send succeeds and the other end doesn't return a pong within a
certain interval, the connection has been closed.

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
Recognizing / Not Recognizing the Disk Drives Bill Coleman Computer Support 1 05-31-2004 07:36 AM



Advertisments