I am having a problem with my client server program using sockets in java. So I want the client to send the string "chef", and in the server I want it to send something back if the client sent "chef", otherwise do something else. The problem is the string sent from the client to the server does not match for some odd reason. This is the snip of code I have on the client class, to send the string:
PrintStream PS=new PrintStream(sock.getOutputStream());
PS.println("chef");
In the server I have this snippet:
Socket sock=socket.accept();
InputStreamReader IR=new InputStreamReader(sock.getInputStream());
BufferedReader BR=new BufferedReader(IR);
String message="";
message=BR.readLine();
if (message=="chef")
{
PrintStream ps=new PrintStream(sock.getOutputStream());
ps.println("Chef Connected");
}
else
{
System.out.println(message);
}
So the problem is the server keeps going to the else statement even thought I am sending the correct string "chef". I used System.out.println(message) in the else and it prints the string "chef". So I am very lost at why this is happening. Hopefully I was clear, and any help or clarification would be greatly appreciated.