Can't get sockets to work

Lincoln Spiteri lincoln.spiteri@st.com
Tue May 25 09:50:00 GMT 1999


That's right, this started off as a baby HTTP server where multiple prints are
made, no luck there so I tried somthing simpler ...  

I have tried looking at the OutputStream, PrintStream, BufferedOutputStream,
FileOutputStream, FilteredOutputStream code with little luck so far. I really
need a good debugger, will the latest GDB work with DDD? Quick
System.out.printlns here and there will wreck havock with these classes.
Understandably you get nice recursive calls all the way to segmentation!

For now I guess I will initialise the PrintStream with the auto flush
flag set true. I would really like to understand what the difference bettween
the flush and print are.  It seems flush will call a write whilst print will
call writeChars in PrintStream where things get done with an encoding
converter, does the converter do the write itself?

Regards

Lincoln

On Tue, 25 May 1999, bryce@albatross.co.nz wrote:
> 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();
>                       System.out.println(request);
> 
>                       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
> implemented?
> 
> regards
> 
>   [ bryce ]
--
------------------------------------------------------------------------------

Lincoln Spiteri

Manufacturing Systems
STMicroelectronics, Malta

e-mail: lincoln.spiteri@st.com

------------------------------------------------------------------------------


More information about the Java mailing list