我爲學校製作了這個程序,它涉及到一個telnet服務器。當我運行它時,它會返回奇怪的字符,如ÿûÿû
。下面是輸出:Telnet服務器返回奇怪的字符
Client connected with the IP /127.0.0.1
Client /127.0.0.1 has entered the username ÿûÿû ÿûÿû'ÿýÿûÿýdcole.
我的代碼:
Socket client = serv.accept();
InetAddress clientip = client.getInetAddress();
out("Client connected with the IP " + clientip);
InputStream clientinput = client.getInputStream();
OutputStream clientoutput = client.getOutputStream();
Scanner in = new Scanner(clientinput);
clientoutput.write("Please enter your username: ".getBytes());
String username = in.nextLine();
out("Client " + clientip + " has entered the username " + username + ".");
String pass = "Please enter the password for " + username + ": ";
clientoutput.write(pass.getBytes());
String password = in.nextLine();
if (username.equals("dcole") && password.equals("test")) {
clientoutput.write("\r\nCorrect password!".getBytes());
} else {
clientoutput.write("\r\nIncorrect password!".getBytes());
}
1.不,我用windows。 2.不,我只使用QWERTY鍵盤按鍵(英文)。 – cheese5505 2012-04-11 02:49:13
此外,這不是作業:P – cheese5505 2012-04-11 02:53:13
如何在我上面編輯的答案中嘗試點3 - 也許從創建時流是髒。 – wattostudios 2012-04-11 02:58:24