title: Server Socket blocks after first recived data
body: <p>I want to ask why the server is showing only the first time one of the clients send data ,my intent is to have two clients and just want to send some integer ,the server to read it and then send it back to the other client and then to wait the this client to send info and send it to the other client (toggling them).But only the first time the data is sended ,it is read on the server ? </p>
  
  <p>Server :</p>
  
  <pre><code>import java.io.DataInputStream;
  import java.io.DataOutputStream;
  import java.io.IOException;
  import java.net.ServerSocket;
  import java.net.Socket;
  
  
  public class Server {
  
      private ServerSocket serv;
      private DataInputStream inFromClient1;
      private DataOutputStream outToClient1;
      private DataInputStream inFromClient2;
      private DataOutputStream outToClient2;
  
      public Server(){
          try {
              serv=new ServerSocket(8000);
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  
      public void listen() throws IOException{
          System.out.println("Listening for connections");
          new Thread(new Runnable() {
  
              @Override
              public void run() {
                  // TODO Auto-generated method stub
                  while(true){
                      Socket sock1;
                      Socket sock2;
                      try {
                          sock1 = serv.accept();
                          sock2=serv.accept();
                          handleSession(sock1,sock2);
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
  
                  }
              }
          }).start();
  
      }
      public void handleSession(Socket s1,Socket s2) throws IOException{
          DataInputStream in1=new DataInputStream(s1.getInputStream());
          DataOutputStream out1=new DataOutputStream(s1.getOutputStream());
  
          DataInputStream in2=new DataInputStream(s1.getInputStream());
          DataOutputStream out2=new DataOutputStream(s1.getOutputStream());
          while(true){
  
              int inint1=in1.readInt();
              System.out.println("Recived from 1 " + inint1);
              System.out.println("Sending to 2 ");
              out2.writeInt(in1.readInt());
              int inint2=in2.readInt();
              System.out.println("Recived from 2 " + inint2);
              System.out.println("Sending to 1 ");
              out1.writeInt(inint2);
          }
      }
      public static void main(String[] args) throws IOException {
          new Server().listen();
      }
  }
  
  Client : 
  
  import java.awt.Dimension;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.DataInputStream;
  import java.io.DataOutputStream;
  import java.io.IOException;
  import java.net.Socket;
  import java.net.UnknownHostException;
  import java.util.Scanner;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  
  public class Client extends JFrame implements ActionListener{
  
      private JPanel mainPanel;
      private JButton[] buttons;
      private Socket socket;
      private int number;
      private DataInputStream fromServer;
      private DataOutputStream toServer;
      private boolean myTurn=true;
  
      public Client() throws UnknownHostException, IOException{
          mainPanel=new JPanel(new GridLayout(3,3));
          socket=new Socket("localhost",8000);
          add(mainPanel);
          addbuttons();
          setSize(new Dimension(500,400));
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setVisible(true);
      }
  
      private void addbuttons(){
          buttons=new JButton[9];
          for(int i=1;i&lt;10;i++){
              buttons[i-1]=new JButton("Rectangle " + i);
              buttons[i-1].addActionListener(this);
              mainPanel.add(buttons[i-1]);
          }
      }
      public void actionPerformed(ActionEvent arg0) {
          JButton butt=(JButton) arg0.getSource();
          String str=butt.getText();
          String[] splitStr=str.split(" ");
          number=Integer.parseInt(splitStr[1]);
          System.out.println(number);
      }
  
      public void start() throws IOException{
          fromServer=new DataInputStream(socket.getInputStream());
          toServer=new DataOutputStream(socket.getOutputStream());
  
          new Thread(new Runnable() {
  
              @Override
              public void run() {
                  Scanner in=new Scanner(System.in);
                  while(true){
                      System.out.println("Write some integer");
                      int inint=in.nextInt();
                      System.out.println("Before " + myTurn);
                      if(myTurn){
                          try {
                              toServer.writeInt(inint);
                          } catch (IOException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          myTurn=false;
                      }
                      else{
                          int fromServint=0;
                          try {
                              fromServint=fromServer.readInt();
                          } catch (IOException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          System.out.println("Recived integer " + fromServint);
                          buttons[fromServint].setText("Some new Text");
                          myTurn=true;
                      }
                      System.out.println("After " + myTurn);
                  }
              }
          }).start();
      }
  
      public static void main(String[] args) throws UnknownHostException, IOException {
          new Client().start();
      }
  }
  </code></pre>