title: Server not receiving in socket communication
body: <p>I'm trying to make a Java program in which the server generates a random number and, after establishing a connection with a client, lets it guess the number. However, they both don't seem able to receive each others' messages. <br>
  Server side:</p>
  
  <pre><code>package numberguessserv;
  
  import java.net.*;
  import java.io.*;
  import java.util.Random;
  import java.util.Scanner;
  
  public class NumberGuessServ {
  
      public static void main(String[] args) {
          Scanner inpkb = new Scanner(System.in);
          Random randomGenerator = new Random();
          int randomNum = randomGenerator.nextInt(10);
          String number = Integer.toString(randomNum);
          int port;
          boolean isGuessed = false;
          String msgReceived;
          Socket connect = new Socket();
          System.out.print("port: ");
          port = inpkb.nextInt();
          try {
              ServerSocket clSock = new ServerSocket(port);
              System.out.println("Waiting...");
              connect = clSock.accept();
              System.out.println("Connection established with"+connect.getInetAddress());
              InputStreamReader isr = new InputStreamReader(connect.getInputStream());
              BufferedReader isrBuff = new BufferedReader(isr);
              OutputStreamWriter osw = new OutputStreamWriter(connect.getOutputStream());
              BufferedWriter oswBuff = new BufferedWriter(osw);
              while (!isGuessed) {
                  msgReceived = isrBuff.readLine();
                  System.out.println("Number received: "+msgReceived);
                  if (msgReceived.equals(number)) {
                      isGuessed = true;
                      oswBuff.write("Right!");
                      oswBuff.flush();
                  }
                  else {
                      oswBuff.write("Wrong!");
                      oswBuff.flush();
                  }
                  if (isGuessed)
                      System.out.println("Number was guessed right.");
                  else
                      System.out.println("Number was guessed wrong.");
                  }
              }
              catch (Exception ex) {
                  System.out.println("An exception has occurred: "+ex);
              }
              finally {
                  try {
                      connect.close();
                  }
                  catch (Exception ex) {
                      System.out.println("An exception has occurred: "+ex);
                  }
             }
        }
   }
  </code></pre>
  
  <p>Client side:</p>
  
  <pre><code>package numberguessclient;
  
  import java.io.*;
  import java.util.Scanner;
  import java.net.*;
  
  public class NumberGuessClient {
  
      public static void main(String[] args) {
          Scanner inpkb = new Scanner(System.in);
          int port;
          String IP;
          boolean isGuessed = false;
          String number, msg;
          Socket serv = new Socket();
          System.out.print("IP: ");
          IP = inpkb.next();
          System.out.print("port: ");
          port = inpkb.nextInt();
          try {
              serv = new Socket(IP,port);
              System.out.println("Connetion established with"+serv.getInetAddress());
              InputStreamReader isr = new InputStreamReader(serv.getInputStream());
              BufferedReader isrBuff = new BufferedReader(isr);
              OutputStreamWriter osw = new OutputStreamWriter(serv.getOutputStream());
              BufferedWriter oswBuff = new BufferedWriter(osw);
              while (!isGuessed) {
                  System.out.print("number: ");
                  number = inpkb.next();
                  oswBuff.write(number);
                  oswBuff.flush();
                  System.out.println("Number sent.");
                  msg = isrBuff.readLine();
                  System.out.println("The reply was received: "+msg);
                  if (msg.equals("Right!")) {
                      isGuessed = true;
                      System.out.println(msg);
                  }
                  else {
                      System.out.println(msg+"\nTry again...");
                  }
              }
          }
          catch (Exception ex) {
              System.out.print("An exception has occurred: "+ex);
          }
          finally {
              try {
                  serv.close();
              }
              catch (Exception ex) {
                  System.out.print("An exception has occurred: "+ex);
              }
          }
      }
  }
  </code></pre>