For example if I assign multiple lines to a string as so:
while ((line = reader.readLine()) != null)
{
output += line + \"\\n\";
}
why not just move this to outside the while loop?
System.out.print("Enter your choice: ");
fromClient = stdIn.readLine().trim();
There is another mistake in code: while ((fromServer = input.readLine())+"\n" != null)
. It will be always true. You should only check: while ((fromServer = input.readLine()) != null)
.
Also if I understand your requirements correctly, your code should be something like below:
String fromServer = "";
String line;
while ((line = input.readLine()) != null) {
fromServer += line + "\n"; // collect multiline strings into fromServer
}
System.out.println("Server: " + fromServer);
if (fromServer.equals("Bye"))
break;
System.out.print("Enter your choice: ");
fromClient = stdIn.readLine().trim();
if(fromClient.equals("1"))
{
System.out.println("Client: " + fromClient);
output.println(fromClient);
}