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. Advertisements

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,161
    Roedy Green
    Sep 27, 2005
  2. bugbear
    Replies:
    0
    Views:
    1,251
    bugbear
    Aug 28, 2003
  3. Cigdem
    Replies:
    2
    Views:
    3,759
    Cigdem Savaseri-Brackmann
    Mar 17, 2005
  4. MBR
    Replies:
    4
    Views:
    585
    red floyd
    Oct 12, 2004
  5. Matthias Braun

    Parsing XML with Xerces-C++

    Matthias Braun, Oct 14, 2006, in forum: XML
    Replies:
    1
    Views:
    4,514
    spiff
    Oct 15, 2006
  6. Matthias Braun

    Parsing XML with Xerces-C++

    Matthias Braun, Oct 15, 2006, in forum: XML
    Replies:
    3
    Views:
    1,012
    Matthias Braun
    Oct 16, 2006
  7. johnmmcparland

    Parsing XML Schema with Xerces-J

    johnmmcparland, Apr 9, 2009, in forum: XML
    Replies:
    1
    Views:
    1,206
    Martin Honnen
    Apr 9, 2009
  8. Erik Wasser
    Replies:
    5
    Views:
    806
    Peter J. Holzer
    Mar 5, 2006
Loading...