QUOTE(codemonkey83 @ 4 Jul, 2007 - 02:48 PM)

Hi all, it's been a while.
I'v been working on writing my own mud client in Java, primarily to be used for the Mud Achaea.
I "borrowed" the telnet client code from the Java Cookbook in order to get an idea ow writing the basic client might work, but I seem to be having issues getting the prompt to display until after I type a command and was wondering if someone might be able to help me see what needs to be done. Here's the basic code(uncommented) from the Java Cookbook.
CODE
import java.net.*;
import java.io.*;
public class Telnet {
String host;
int portNum;
public static void main(String[] argv) {
new Telnet().talkTo(argv);
}
private void talkTo(String av[]) {
if (av.length >= 1)
host = av[0];
else
host = "localhost";
if (av.length >=2)
portNum = Integer.parseInt(av[1]);
else
portNum = 23;
System.out.println("Host " + host + "; port " + portNum);
try {
Socket s = new Socket(host, portNum);
new Pipe(s.getInputStream(), System.out).start();
new Pipe(System.in, s.getOutputStream()).start();
} catch (IOException e) {
System.out.println(e);
return;
}
System.out.println("Connected OK");
}
}
class Pipe extends Thread {
BufferedReader is;
PrintStream os;
Pipe(InputStream is, OutputStream os) {
this.is = new BufferedReader(new InputStreamReader(is));
this.os = new PrintStream(os);
}
public void run() {
String line;
try {
while ((line = is.readLine()) != null) {
os.print(line);
os.print("\r\n");
os.flush();
}
} catch (IOException e) {
System.out.println(e);
}
}
}
Any help would be appreciated.
I have recently revisted this project and began working on a system from scratch. I am still finding it difficult to get the server's prompt to display until after input something and hit enter, which results in something like.
CODE
2
Enter an option or enter your character's name. ��
The prompt should be:
CODE
Enter an option or enter your character's name.
If the suggested solution will in fact work for this, how would I do this?