0

こんにちは、私は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";
        }
    }
}
4

1 に答える 1