[MUD-Dev] Modular Design Issues RFC

Kwon Ekstrom justice at softhome.net
Tue Mar 6 02:06:39 CET 2001


----- Original Message -----
From: "Ryan Rhodes" <ryanshaerhodes at hotmail.com>
To: <mud-dev at kanga.nu>
Sent: Thursday, March 01, 2001 6:12 AM
Subject: Re: Re[2]: [MUD-Dev] Modular Design Issues RFC

> Scion Altera wrote:
>> Thursday, February 15, 2001, 3:12:42 AM, Ryan Rhodes wrote:

>>> The only way to generate a Connection Closed exception for thread
>>> death is to be constantly blocking for input.  Java doesn't allow
>>> you to stop blocking once you have started, nor does it provide
>>> any sort of asynchronous method to read input.  You can check for
>>> the ammount of input available before you read it, reading in just
>>> enough to prevent blocking, but then you can't capture link death.

>> That is not entirely true. You can poll connections in Java
>> (checking whether input is available or not), and it is true that
>> you cannot tell if a connection is dead by reading from
>> it. However, if you try to write to a connection that is dead, you
>> get an IOException thrown.

> Your like the third person that has told me they were catching link
> death off of writes instead of reads.  I just went back and tried it
> again and I still can't get an IOException from a print or println.
> I'm starting to wonder if this is particular to Linux???  What
> Stream object are you using for your connections?  PrintWriter?
> PrintStream?  something else?  I've tried this from the begining and
> it has never worked.  If you can tell me how, please do.

Some writers catch the exception and set an error boolean.  The
PrintWriter is one of those, check the API for the writer you're
using.  Here's what it shows for PrintWriter:

  boolean checkError()  Flush the stream and check it's error state.

I was using the printwriter until I decided to switch to a
non-blocking system, in attempting to find an efficient way to detect
disconnects, I discovered that the writer adds alot of additional
overhead to your stream.  What I do now is pass the text directly to
the OutputStream, try:

  void send(String txt) {
    try {
      out.write(txt.getBytes());
    } catch(IOException e) {
      e.printStackTrace();
    }
  }
  void sendln(String txt) {
    send(txt+"\n\r");
  }

Naturally out is the output stream for your socket.

-- Kwon Ekstrom

_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the mud-dev-archive mailing list