Can't get sockets to work
Mon May 24 23:38:00 GMT 1999
Warren Levy wrote:
> On Mon, 24 May 1999, Lincoln Spiteri wrote:
> > I am trying to get the code below to work, it is a simple server app which
> > echos any text it receives and then dies. The problem is that if compile this
> > and run it with the JDK all is ok. I telnet my machine on port 7070 type in
> > something and get 'Echo: something' back.
> > If I try this with GCJ the server runs but when I telnet to it, it recieves my
> > input but the 'Echo: something' does not appear on the client side.
> Lincoln, try doing an os.flush(); right after your os.print of the echo
> request. I suspect that the close of the Socket is not flushing the
> output as is apparently happening in the JDK.
The problem is not just an issue with flushing upon closing the socket. If you take
Lincoln's test code and add something like the following loop:
for (int i=0; i<5; i++)
String request = is.readLine();
os.print( "Echo: " + request + "\r\n");
it won't actually send any data at all until os.flush() is called, unless you send
it a very long input, in which case it seems to partially clear out the buffer. In
the JDK, the data will allways be sent immediatly. I havn't investigated further,
but perhaps this is a problem with the way some of the OutputStream classes are
[ bryce ]
More information about the Java