Добрый день, все, что я новичок в java, и я хотел бы знать, может ли кто-нибудь помочь мне с этой проблемой. У меня есть сервер, и он получает информацию от клиента, но оператор if, чтобы проверить значение, которое был принят не работает.socket send and retrieve
Вот мой код для сервера.
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";
}
}
}
Спасибо, что сейчас работает. – tiaan3365