title: 1 server 2 clients java
body: <p>i want to make a game with 2 players .i will use udp server and 2 clients and i dont 
  know how to connect 2 clients to 1 server at the same time and how they will communicate.
  I will use only java.At last how the mouse click will syncronize with server</p>
  
  <pre><code>  public void mousePressed(MouseEvent event) { 
    }  
    public void mouseReleased(MouseEvent event) { 
    }  
    public void mouseEntered(MouseEvent event) { 
    }  
    public void mouseExited(MouseEvent event) { 
    } 
  </code></pre>
  
  <p>the server </p>
  
  <pre><code>public class Provider {
  public ServerSocket providerSocket;
  Socket connection = null;
  ObjectOutputStream out;
  ObjectInputStream in;
  String message;
  String[] torino={"null","null"};
  Provider() {}
  void run()
  {
      try {
          //1. creating a server socket (8080=port , 2 =number of connections)
          providerSocket = new ServerSocket(8080, 2 );
          //2. Wait for connection
          System.out.println("Waiting for connection");
          connection = providerSocket.accept();
          System.out.println("Connection received from " + connection.getInetAddress().getHostName());
          //3. get Input and Output streams
          out = new ObjectOutputStream(connection.getOutputStream());
          // flush= clean the object out
          out.flush();
          in = new ObjectInputStream(connection.getInputStream());
          sendMessage("Connection successful");
          //4. The two parts communicate via the input and output streams
          try {
              //take the message from client
              message = (String)in.readObject();
              if (torino[0]=="null") 
                  torino[0]=message;
              } else if (torino[1]=="null") {
                  torino[1]=message;              
              }
          }
          catch(ClassNotFoundException classnot) {
              System.err.println("Data received in unknown format");
          }
      } catch(IOException ioException) {
          ioException.printStackTrace();
      }
      finally {
          //4: Closing connection
          try {
              in.close();
              out.close();
              providerSocket.close();
          } catch(IOException ioException) {
              ioException.printStackTrace();
          }
      }
  }
  //method to send messages from server to clients
  void sendMessage(String msg)
  {
      try {
          out.writeObject(msg);
          out.flush();
          System.out.println("server&gt;" + msg);
      }
      catch(IOException ioException) {
          ioException.printStackTrace();
      }
  }
  
  //main method
  public static void main(String args[])
  {
      Provider server = new Provider();
      while(true) {
          server.run();
      }
  }
  </code></pre>