Mud Client Input Problems
I'm in the process of writing a Java mud client and had a problem where occasionally I'll get irregular characters (as such followed by the rectangular newline) or when I am being prompted for input the message prompting me does not actually come through until after I answer its prompt. I was wondering how I would go about fixing this. Most of everything comes through normally, except ansi colors but I'm still working on that. I'm using a BufferedReader to read from the socket (as a side note).
[519 byte] By [
deathDrop] at [2007-9-30 12:33:21]

For displaying to my client I am using a JTextPane/DefaultStyledDocument at the moment, so I use doc.insertString() to display any user typed input as well as output from the mud. Here's my inner class which actually does the getting/sending of information:
public class Target extends Thread{
private BufferedReader in;
private PrintWriter out;
private Socket socket;
private String msg;
private boolean proceed=true;
public Target() {
//hostname = "anguish.org";
//port = 2000;
hostname = "mud.evermore.de";
port = 23;
socket = SocketOpener.openSocket(hostname, port, 6000);
if(socket == null) {
echo(sysMsg + "Could not connect to " + hostname + ":" + port);
System.err.println("Couldn't connect to " + hostname + ":" + port);
}
else {
try{ in = new BufferedReader(new InputStreamReader(socket.getInputStream())); }
catch(IOException e) {System.err.println("Couldn't set Input Stream");}
try{ out = new PrintWriter(socket.getOutputStream(), true); }
catch(IOException e) { System.err.println("Couldn't set Output Stream");}
setTitle(hostname+":"+port);
}
}
public void closeConnection() {
if (socket == null) return;
try { socket.close(); }
catch(IOException e) {}
socket = null;
}
public void run() {
while(proceed && in!=null) {
try { msg = in.readLine(); }
catch(InterruptedIOException e) { echo("BLASJAKS"); continue; }
catch(IOException e) {
proceed = false;
echo(sysMsg + "Connection interrupted.");
setTitle("Not Connected");
continue;
}
if(msg == null) {
proceed = false;
echo(sysMsg + "Connection lost.");
setTitle("Not Connected");
continue;
}
echo(msg + ls);
}
}
public void sendCmd(String cmd) {
try {echo(ls + cmd); out.println(cmd); } //echo(ls + "> ");}
catch(Exception e) {
proceed = false;
echo(sysMsg + "Connection lost.");
setTitle("Not Connected");
}
}
}
> I have no idea what all the RFCs for Telnet are... so
> my guess is no.
Right, what you are getting are commands by the host to find out what you (the client) support, or requesting that you enable and disable a function (Local Echo etc).
You could either implement this yourself [url http://www.faqs.org/rfcs/rfc854.html]RFC 854[/url] would be the place to start, you could look at some of the other Java based telnet implementations. Or finally, you could take a look over at [url http://jakarta.apache.org/commons/net/]Jakarta Commons Net[/url].
Good luck.
Mlk
mlk at 2007-7-4 16:17:25 >
