我正在尝试制作一个套接字服务器,我正在通过腻子连接到该服务器。每当我输入“hi”时,它会说“no”而不是“hi”,我希望它这样做。我在一个 java 网站上找到了这个。如果你能告诉我我做错了什么,那就太好了。谢谢!
int port = 12345;
ServerSocket sock = new ServerSocket(port);
System.out.println("Server now active on port: " + port);
Socket link = sock.accept();
System.out.println("Interface accepted request, IP: " + link.getInetAddress());
BufferedReader input = new BufferedReader(new InputStreamReader(link.getInputStream()));
PrintWriter output = new PrintWriter(link.getOutputStream(), true);
output.println("ISEEYOU");
String inputLine;
Thread.sleep(1500);
while((inputLine = input.readLine()) != null) {
if(inputLine.equals("hi")) {
output.println("hi");
}else{
output.println("no");
}
}