XML parsing with Xerces

Discussion in 'XML' started by Kane, May 12, 2004.

  1. Kane

    Kane Guest

    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!
     
    Kane, May 12, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    3
    Views:
    2,015
    Roedy Green
    Sep 27, 2005
  2. bugbear
    Replies:
    0
    Views:
    1,070
    bugbear
    Aug 28, 2003
  3. cvissy
    Replies:
    0
    Views:
    639
    cvissy
    Nov 16, 2004
  4. Cigdem
    Replies:
    2
    Views:
    3,538
    Cigdem Savaseri-Brackmann
    Mar 17, 2005
  5. MBR
    Replies:
    4
    Views:
    535
    red floyd
    Oct 12, 2004
Loading...

Share This Page