G
Guest
I have a servlet-applet couple which communicate via a server Socket and
client Socket couple. In the functioning implementation the servlet
listens on the ServerSocket, opens a clientSocket when the applet
connects, and opens onto it two streams. The applet does the same on its
side.
PrintWriter appletout = new
PrintWriter(mySocket.getOutputStream(), true);
BufferedReader appletin = new BufferedReader(new
InputStreamReader(mySocket.getInputStream()));
The applet tests appletin.ready() before reading with
appletin.readLine(). In some cases it has to test a few times before it
becomes ready, but it works.
Now I want to write a DIFFERENT servlet-applet couple, which exchanges
some complex binary data.
In this case on the servlet side I thought I should have an
ObjectOutputStream
appletout = new ObjectOutputStream(clientSocket.getOutputStream()) ;
and on the applet side I should have
appletin = new ObjectInputStream(mySocket.getInputStream() );
I expected that, in order to test that the stream is ready, I had to
replace the ready() call with a appletin.available() != 0
It occurs instead that this is not true, apparently (I'm currently
testing between two standalone applications) available() always returns
zero, and the pseudo-applet can immediately issue a
s = (String) appletin.readObject() ;
as soon as the pseudo-servlet has e.g. issued
appletout.writeObject((String) "READY");
appletout.flush();
(is my assumption that each write shall be immediately followed by a
flush ?)
How does one use available() or any other way to find that there is
pending data on the input channel ?
client Socket couple. In the functioning implementation the servlet
listens on the ServerSocket, opens a clientSocket when the applet
connects, and opens onto it two streams. The applet does the same on its
side.
PrintWriter appletout = new
PrintWriter(mySocket.getOutputStream(), true);
BufferedReader appletin = new BufferedReader(new
InputStreamReader(mySocket.getInputStream()));
The applet tests appletin.ready() before reading with
appletin.readLine(). In some cases it has to test a few times before it
becomes ready, but it works.
Now I want to write a DIFFERENT servlet-applet couple, which exchanges
some complex binary data.
In this case on the servlet side I thought I should have an
ObjectOutputStream
appletout = new ObjectOutputStream(clientSocket.getOutputStream()) ;
and on the applet side I should have
appletin = new ObjectInputStream(mySocket.getInputStream() );
I expected that, in order to test that the stream is ready, I had to
replace the ready() call with a appletin.available() != 0
It occurs instead that this is not true, apparently (I'm currently
testing between two standalone applications) available() always returns
zero, and the pseudo-applet can immediately issue a
s = (String) appletin.readObject() ;
as soon as the pseudo-servlet has e.g. issued
appletout.writeObject((String) "READY");
appletout.flush();
(is my assumption that each write shall be immediately followed by a
flush ?)
How does one use available() or any other way to find that there is
pending data on the input channel ?