XML parsing with Xerces

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top