This is a Client-Server GUI Application, here I want to send and receive messages between them. the condition is , when the client send "Hello" to server , the server only reply with this message "Hello Client, I am server". so, how can I use if else in this case?
public void startRunning() throws ClassNotFoundException
{
try
{
server = new ServerSocket(port, totalClients);
while(true)
{
try
{
status.setText(" Waiting for Someone to Connect...");
connection = server.accept();
status.setText(" Now Connected to " + connection.getInetAddress().getHostName());
output = new ObjectOutputStream(connection.getOutputStream());
//output.flush();
input = new ObjectInputStream(connection.getInputStream());
whileChatting();
}catch(EOFException eofException)
{
}
}
}
catch(IOException ioException)
{
}
}
private void whileChatting() throws IOException, ClassNotFoundException
{
String message="";
jTextField1.setEditable(true);
do{
message = (String) input.readObject();
chatArea.append("\n"+message);
}
while(!message.equalsIgnoreCase("Client - Quit"));
}
private void sendMessage(String message)
{
try
{
output.writeObject("Server - " + message);
output.flush();
chatArea.append("\nServer - " + message);
}
catch(IOException ioException)
{
chatArea.append("\n Unable to Send Message");
JOptionPane.showMessageDialog(null,"Unable to Send Message", "Warning", JOptionPane.WARNING_MESSAGE);
}
}