美好的一天,我是 java 新手,我想知道是否有人可以帮助我解决这个问题我有一个服务器,它从客户端接收信息,但是我的 if 语句检查传递的值不起作用。
这是我的服务器代码。
Session(Socket s){
soc = s;
try{
br = new BufferedReader(new InputStreamReader(soc.getInputStream()));
pw = new PrintWriter(new BufferedOutputStream(soc.getOutputStream()),true);
pw.println("Welcome");
}catch(IOException ioe){
System.out.println(ioe);
}
if(runner == null){
runner = new Thread(this);
runner.start();
}
}
public void run(){
while(runner == Thread.currentThread()){
try{
String input = br.readLine().toString();
if(input != null){
String output = Protocol.ProcessInput(input);
pw.println(output);
System.out.println(input);
if(output.equals("Good Bye")){
runner = null;
pw.close();
br.close();
soc.close();
}
**This if statement doesn't work ↓**
if(Protocol.ProcessInput(input).equalsIgnoreCase("tiaan")){
// System.exit(0);
System.out.println("Got tiaan!!!");
}
}
}catch(IOException ie){
System.out.println(ie);
}
try{
Thread.sleep(10);
}catch(InterruptedException ie){
System.out.println(ie);
}
}
}
}
class Protocol{
static String ProcessInput(String input){
if(input.equalsIgnoreCase("Hello")){
return "Well hello to you to";
}else{
return "Good bye";
}
}
}