title: Accepting multiple clients in Java TCP
body: <p>I want to accept multiple clients in a Java TCP program. So I used a <code>while</code> loop to accept multiple clients. But the problem is I cannot connect the nodes with the server randomly. I used to connect the clients one by one in order. So how to use the switch case to connect the nodes with my server randomly?</p>
  
  <p>My <code>while</code> Loop:</p>
  
  <pre><code>int port=7000;
  
  while(true)
  {
      try
      {
          node1=new ServerSocket(port+10);
          Socket check1=node1.accept();
          System.out.println("CLIENT A IS CONNECTED");
      }
      catch(Exception e)
      {
          System.out.println(e);
      }
  
      try
      {
          ServerSocket soc2=new ServerSocket(port+20);
          Socket check2=soc2.accept();
          System.out.println("CLIENT B IS CONNECTED");
      }
      catch(Exception e)
      {
          System.out.println(e);
      }
  
      try
      {
          node3=new ServerSocket(port+30);
          Socket check3=node3.accept();
          System.out.println("CLIENT C IS CONNECTED");
      }
      catch(Exception e)
      {
          System.out.println(e);
      }
  
      try
      {
          node4=new ServerSocket(port+40);
          Socket check4=node4.accept();
          System.out.println("CLIENT D IS CONNECTED");
      }
      catch(Exception e)
      {
          System.out.println(e);
      }
  
      try
      {
          node5=new ServerSocket(port+50);
          Socket check5=node5.accept();
          System.out.println("CLIENT E IS CONNECTED");
      }
      catch(Exception e)
      {
          System.out.println(e);
      }
  </code></pre>
  
  <p>But When I use this <code>JavaNetBindexception</code> is occurring when I connect it with E client.</p>