This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Can't get sockets to work


>>>>> "Lincoln" == Lincoln Spiteri <lincoln.spiteri@st.com> writes:

Lincoln> I really need a good debugger, will the latest GDB work with
Lincoln> DDD?

I don't know, but you could try it.

Lincoln> For now I guess I will initialise the PrintStream with the
Lincoln> auto flush flag set true.

I didn't look at the code closely enough before.  You wrote this:

   os.print( "Echo: " + request + "\r\n");
   conn.close(); 

It's probably a bad idea to close the file underlying the
PrintStream.  Instead you should close the PrintStream.

Of course, that won't solve your problem.  You still have to flush.  I
recommend writing:

   os.flush();
   os.close();

Lincoln> I would really like to understand what the difference
Lincoln> bettween the flush and print are.  It seems flush will call a
Lincoln> write whilst print will call writeChars in PrintStream where
Lincoln> things get done with an encoding converter, does the
Lincoln> converter do the write itself?

PrintStream uses a buffer internally.

The buffer is only flushed at certain points: when it is full,
(sometimes) when a newline is printed, or when flush() is called.

This is documented in the Java Class Libraries book.

I recommend not worrying about the writeChars method.  That is an
internal implementation detail.

Tom

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]