我为一所学校制作了这个程序,它涉及一个 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());
}