Using Sockets with BufferedInputStream

Hi,

Many thanks in advance for any help or advice. I have been struggling with this for a while now.

I have data comming in from a Socket. I create a BufferedInputStream like this:

inputStream =new BufferedInputStream( socket.getInputStream() );

The class that this code is in extends Thread, and in the run method i have:

while(true )

{

try

{

inputSource =new InputSource( inputStream );

responseXML.parseClientData( inputSource, client.getID() );

}

catch( Exception e )

{

System.out.println("run.Error: " + e );

}

}

The class responseXML takes the stream and tries to parse the XML as follows:

publicvoid parseClientData( InputSource dataFromFlash,int clientID )

{

System.out.println("parseClientData" + clientID );

try

{

xmlReader.parse( dataFromFlash );

}

catch( Exception e )

{

System.out.println("parseClientData.Error: " + e );

}

}

My problem:

The above method (parseClientData) is getting called over and over again - it is stuck in an infinite loop.

And this error is caught in the above methodt:

parseClientData.Error: java.io.IOException: Stream closed

Any ideas? I have been struggling with this for far too long.

I thnik it might be to do with blocking and non-blocking input streams.

When i used a noraml BufferedReader - i didn't have this problem.

Thanks.

Regards, Custom

Message was edited by:

custom

Message was edited by:

custom

[2381 byte] By [customa] at [2007-10-3 2:09:27]
# 1

Come on buddy wake up!

You have a while loop that NEVER exits and exception blocks that don't do anything productive and this error message "ClientData.Error: java.io.IOException: Stream closed" tells you exactly what the problem is.

Do you think maybe you should exit the while loop if an exception is thrown? Do you? Perhaps? Maybe?

cotton.ma at 2007-7-14 19:08:19 > top of Java-index,Archived Forums,Socket Programming...
# 2
Besides the above you should send messages not data.
jschella at 2007-7-14 19:08:19 > top of Java-index,Archived Forums,Socket Programming...
# 3
Also I believe the XML parse methods close the input stream.
ejpa at 2007-7-14 19:08:19 > top of Java-index,Archived Forums,Socket Programming...