The code below is in server side. It could handle client request and then show the client input in my console.
Yet, the problem appears...
The console shows the string "hello from clientA" successfully. But, I cannot use "if" to analyze this word.
My objective is to show "ok" in console if it is a request from "clientA". To conclude that, the program does not reach "System.out.println("ok")" even though it matches the condition.
Please help me )...(
Thanks.
while(true)
{
Socket server = null;
try
{
server = serverSocket.accept();
DataInputStream in =
new DataInputStream(server.getInputStream());
obtain=in.readUTF();
DataOutputStream out =
new DataOutputStream(server.getOutputStream());
out.writeUTF("server say hello to you");
System.out.println(obtain);//the console show "hello from clientA" exactly
if(obtain=="hello from clientA")
{
System.out.println("ok");
}
server.close();
}catch(SocketTimeoutException s)
{
System.out.println("Again");
try {
serverSocket.setSoTimeout(20000);
} catch (IOException e) {
}
}
catch(Exception b)
{
break;
}
}