title: chat UDP client/server program
body: <p>Hi there I'm trying to create a client/server chat program.
  i have three clients and one server, when a client sends some string to the server the server will send this string to the other clients.
  I have created the part where the client sends data to the server but I don't know how to send received data from a client to the other clients.</p>
  
  <p>this is the code I created :</p>
  
  <p>For server:</p>
  
  <pre><code>import java.net.DatagramPacket;
  import java.net.DatagramSocket;
  import java.net.InetAddress;
  
  
  
  public class Server {
  
      private static DatagramSocket serverSocket;
  
      public Server() {
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @param args
       * @throws IOException 
       */
      public static void main(String[] args) throws Exception {
  
          serverSocket = new DatagramSocket(1111);
          byte[] receiveData = new byte[1024];
          byte[] sendData = new byte[1024];
          while(true)
             {
                DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                serverSocket.receive(receivePacket);
                String s = new String( receivePacket.getData());
                System.out.println("Client dit : " + s);
                InetAddress IPAddress = receivePacket.getAddress();
                boolean found = false;
                int port = receivePacket.getPort();
                sendData = s.getBytes();
             }
  
      }
  
  }
  </code></pre>
  
  <p>for clients: (X is the number of client : client1/client2...)</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.DatagramPacket;
  import java.net.DatagramSocket;
  import java.net.InetAddress;
  
  
      public class ClientX {
  
        public ClientX() {
          // TODO Auto-generated constructor stub
        }
  
        /**
         * @param args
         * @throws IOException 
         */
        public static void main(String[] args) throws Exception {
  
          BufferedReader inFromUser =
                   new BufferedReader(new InputStreamReader(System.in));
                DatagramSocket clientSocket = new DatagramSocket();
                InetAddress IPAddress = InetAddress.getByName("localhost");
                System.out.println("Connécté au serveur !");
                byte[] sendData = new byte[1024];
                byte[] receiveData = new byte[1024];
                System.out.print("Ecrire un message: ");
                String s = inFromUser.readLine();
                sendData = s.getBytes();
                DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 1111);
                clientSocket.send(sendPacket);
                DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                clientSocket.receive(receivePacket);
                String message = new String(receivePacket.getData());
                System.out.println(message);
                clientSocket.close();
  
        }
  
      }
  </code></pre>