Exemple de lecture des paquets datagramme avec ‘DatagramSocket’ et ‘DatagramPacket’

Author:

 socket, socket, java, datagram
{filelink=8994}

import java.net.DatagramPacket;
import java.net.DatagramSocket;

class Ex_DatagramSocket
 {

  public static void main(String args[]) throws Exception
 {
    // Création d'un socket datagramme au port 655
    DatagramSocket datagramme = new DatagramSocket(655);

       /*  Afficher quelques informations sur le paquet*/
    byte buff[] = new byte[1024];
    while (true)
    {
     /* Lire les paquets réçus*/
      DatagramPacket paquet_d = new DatagramPacket(buff, buff.length);
      datagramme.receive(paquet_d);
      System.out.println(new String(paquet_d.getData()));
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *