Server Side:

```
try {
    ServerSocket server_socket=new ServerSocket(port_number);
    Socket client_socket= server_socket.accept();
    PrintWriter output = new PrintWriter(client_socket.getOutputStream(),true);
    BufferedReader input = new BufferedReader(new InputStreamReader(client_socket.getInputStream()));
    BufferedReader stdIn=new BufferedReader(new InputStreamReader(System.in));
    String userInput, clientOutput;
    while ((userInput=stdIn.readLine())!="EXIT") {
        if ((clientOutput=input.readLine())!=null) {
            System.out.println("Client: "+clientOutput);
        } if (userInput!=null) {
            output.println(userInput);
            output.flush();
        }
    }
}

```

Client Side:

```
try {
    Socket client_socket= new Socket(hostname,port_number);
    PrintWriter output = new PrintWriter(client_socket.getOutputStream(),true);
    BufferedReader input = new BufferedReader(new InputStreamReader(client_socket.getInputStream()));
    BufferedReader stdIn=new BufferedReader(new InputStreamReader(System.in));

    String userInput,serverOutput;
    while ((userInput=stdIn.readLine())!="EXIT") {
        if ((serverOutput=input.readLine())!=null) {
            System.out.println("Server: "+serverOutput);
        } if (userInput!=null) {
            output.println(userInput);
            output.flush();
        }
    }
}

```

The code in my case makes sense to me, I cant seem to figure out why an enter still needs to be pressed, does it have something to do with `.readLine()`?
I checked out the following post [Server Client in Java only displays message when I press enter](https://stackoverflow.com/questions/31213063/server-client-in-java-only-displays-message-when-i-press-enter), however the solution provided does not fix the situation.

Note: Initially there were no if statements in the while loop. The way I saw this to be an issue was that the while loop may get stuck on one of the lines, waiting for user/server input. Therefore implementing if statements allowed it to skip the waiting portion and re-run the loop.