import java.io.* ; import jbvm.ip2k.*; import java.lang.*; import java.util.*; import java.net.*; //==================================================== class EnvoiMsg extends java.lang.Thread { private DatagramSocket socket; public LinkedList Liste; public final int port_source = 14574; public final int port_destination = 4500; InetAddress adresse=null; DatagramPacket packet; //======================= public EnvoiMsg () { Liste = new LinkedList(); try{ socket = new DatagramSocket(port_source ); }catch (SocketException exc) {System.out.println("Module EnvoiMsg (RJ) DEFAILLANT (Socket)...");} try{ adresse = InetAddress.getByName("Kartal"); }catch(UnknownHostException exc) {System.out.println("Module EnvoiMsg (RJ) DEFAILLANT (Inet Address error)");}; } //======================= public void run() { String ligne; System.out.println("Module EnvoiMsg (RJ)..."); while (true) { while (Liste.size()>0) { ligne = Liste.getFirst().toString(); //System.out.println("Essai envoi RJ ..."); try{ packet= new DatagramPacket( ligne.getBytes(),(ligne.getBytes()).length , adresse , port_destination); socket.send(packet); }catch (IOException exc) {System.out.println("Module EnvoiMsg (RJ) DEFAILLANT (DatagramPacket)...");} // ajouter assurance: Liste.removeFirst(); try{ Thread.sleep(20); }catch (InterruptedException e){} } } } } //==================================================== class ReceptionMsg extends java.lang.Thread { private DatagramSocket socket1; public LinkedList Liste; public final int port_local = 4500; byte[] memoire = new byte[1500]; DatagramPacket reception; //======================= public ReceptionMsg () { Liste = new LinkedList(); try{ socket1 = new DatagramSocket( port_local ); }catch (SocketException exc) {System.out.println("Module ReceptionMsg (RJ) DEFAILLANT (Socket)...");} reception = new DatagramPacket(memoire,memoire.length); } //======================= public void run() { System.out.println("Module ReceptionMsg (RJ)..."); while (true) { try{socket1.receive(reception); }catch (IOException exc) {System.out.println("Module ReceptionMsg (RJ) DEFAILLANT (Recieve)...");} Liste.addLast(new String(memoire)); } } } class RJtest { public static void main(String argv[]) throws IOException { EnvoiMsg EmettreRJ = new EnvoiMsg (); ReceptionMsg RecevoirRJ = new ReceptionMsg (); RecevoirRJ.start(); EmettreRJ.start(); while(true) { if (RecevoirRJ.Liste.size() >0) { EmettreRJ.Liste.addLast(RecevoirRJ.Liste.getFirst()); RecevoirRJ.Liste.removeFirst(); } }} try{ Thread.sleep(10); }catch (InterruptedException e){} }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question