[MUD-Dev] Modular Design Issues RFC

Ryan Rhodes ryanshaerhodes at hotmail.com
Wed Mar 7 03:46:06 CET 2001


Kwon Ekstrom wrote:

> 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.

Ahh, and I was thinking PrintWriter was the one that threw the
Exceptions all this time.  Thanks alot.  So now I can catch link death
on output, but I still can't help thinking of the consequences of
this.  Say I wanted to protect link dead players from entering combat,
but I wanted to make it so if you drop link while already in combat
then you don't get the protection.  Now say Joe Blow loses link in the
room with his attacker, and the very next message to get printed after
he loses link is that he has been attacked.  So, his attacker attacks,
placing him in the combat state and then printing out "So and So
attacks!", which causes him to lose link, but since the link death was
trapped after the attack he won't get protection, even though you lost
link before entering combat.

When I use input for link death I get a link death the second it
happens, and don't have to wait until something prints to your
character.  I admit the above example seems rare, but it could happen.
Is this just the trade off of using output to catch link death?  What
kind of problems like the example above does this cause?  I don't have
any idea how you do this in other languages, but in general, which
method do the majority of servers use for catching link death, input
or output?

> 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");
>   }

When you say a non-blocking system, are you refering to input or
output.  This is a big question I've been having in general.  I have
been under the impression that all output was immediate (non-blocking)
from the games standpoint.  Meaning, control returns from output as
soon as you make the call, it doesn't wait until it actually gets
received on the other end.  Is this true?  If not, are there certain
Writers that block while others don't?  Basically this is to determine
if you need threads to handle output as well as input.

Also, you say the PrintWriter adds extra overhead, but theres a slight
bit of extra overhead in doing that conversion to a byte array and
appending the newline you did above.  In essense, this is being done
for you by the PrintWriter, but I assumed it would be faster to use
the precoded PrintWriter than to basically code this yourself.  Where
is the extra overhead your talking about in PrintWriters and
PrintStreams coming from?


Ryan Rhodes


_______________________________________________
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