package tp4_reseau;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ClientChatMulticast {
	final public static int PORT = 2000;
	final public static String HOST = "238.0.0.23";
	
	public static void main(String[] args) throws IOException {

        final FenetreChat fc = new FenetreChat("La folie du chat");
        
        final MulticastSocket socket = new MulticastSocket(PORT);
        socket.joinGroup(InetAddress.getByName(HOST));
        
        fc.capturerEntree(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if(e.getKeyCode() == KeyEvent.VK_ENTER){
                    byte[] msg = fc.getMessage().getBytes();
                    try {
                        DatagramPacket packet = new DatagramPacket(
                                msg,
                                msg.length,
                                InetAddress.getByName(HOST),
                                PORT
                        );
                        socket.send(packet);
                        fc.effacerChampEnvoi();
                    } catch (UnknownHostException ex) {
                        Logger.getLogger(ClientChatMulticast.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        Logger.getLogger(ClientChatMulticast.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
        
        byte[] buff = new byte[256];
        DatagramPacket packet = new DatagramPacket(buff, buff.length);
        
        for(;;){
            socket.receive(packet);
            String msg = new String(packet.getData(), packet.getOffset(), packet.getLength());
            fc.afficherMessage(msg);
        }
    }

}

@@ -232,32 +232,58 @@
 nHostException;%0A
+import java.util.Scanner;%0A
 import java.util
@@ -298,16 +298,16 @@
 .Level;%0A
-
 import j
@@ -332,16 +332,49 @@
 ogger;%0A%0A
+import javax.swing.JOptionPane;%0A%0A
 public c
@@ -483,17 +483,17 @@
 38.0.0.2
-3
+5
 %22;%0A%09%0A%09pu
@@ -619,32 +619,157 @@
 chat%22);%0A        
+String pseudo = JOptionPane.showInputDialog(%22Pseudo%22, %22Poireau Volant%22) + %22 : %22;%0A        Scanner sc = new Scanner(System.in);
 %0A        final M
@@ -1088,16 +1088,26 @@
 %5B%5D msg =
+ (pseudo +
  fc.getM
@@ -1114,16 +1114,17 @@
 essage()
+)
 .getByte

Update ClientChatMulticast.java