K
Kane
Hi,
I'm using Xerces package to do XML parsing for a small
client/server application and is having a problem with detecting when
the client closes the socket. Basically, the server
will accept and create a thread for each client connection; the
client would then parses one or more XML documents coming into the
socket's stream. Here's the code snippet of the client's run()
method:
.....
InputStreamReader stream = new InputStreamReader(
socket.getInputStream( ) );
MyBufferedReader in = new MyBufferedReader( stream );
InputSource is = new InputSource( in );
....
while ( true )
{
if ( stream.ready( ) )
{
try
{
fParser.parse( is, handler );
}
catch ( SAXException e )
{
//
}
}
Thread.sleep( 10 );
}
....
Using the method mentioned by the Xerce's FAQ, I wrapped
BufferedReader and created an empty close() method so that the socket
connection won't terminate after just one XML document. Everything
seems okay, I was able to parse as many XML documents on the socket
connection as I want; however, when the client terminates the
connection, I was able to detect it. Any ideas?
I have no control over what the other side sending to me; otherwise, I
guess I can have a goodbye message of some sort. Even that wouldn't
solve the problem if the user Ctrl-C out on the other end.
-Thanks!
I'm using Xerces package to do XML parsing for a small
client/server application and is having a problem with detecting when
the client closes the socket. Basically, the server
will accept and create a thread for each client connection; the
client would then parses one or more XML documents coming into the
socket's stream. Here's the code snippet of the client's run()
method:
.....
InputStreamReader stream = new InputStreamReader(
socket.getInputStream( ) );
MyBufferedReader in = new MyBufferedReader( stream );
InputSource is = new InputSource( in );
....
while ( true )
{
if ( stream.ready( ) )
{
try
{
fParser.parse( is, handler );
}
catch ( SAXException e )
{
//
}
}
Thread.sleep( 10 );
}
....
Using the method mentioned by the Xerce's FAQ, I wrapped
BufferedReader and created an empty close() method so that the socket
connection won't terminate after just one XML document. Everything
seems okay, I was able to parse as many XML documents on the socket
connection as I want; however, when the client terminates the
connection, I was able to detect it. Any ideas?
I have no control over what the other side sending to me; otherwise, I
guess I can have a goodbye message of some sort. Even that wouldn't
solve the problem if the user Ctrl-C out on the other end.
-Thanks!