Bonsoir à tous!
j ai un problem avec les packets UDP ,j explique
il y a un fichier sd.java et autre rc.java pour la reception
les deux fichiers sont bien compilés outre j arrive a envoyer un message d'un pc à autre dans même reseau LAN (j ai verifier sur 3 reseaux diffirents )
ce qui est étonant , le message prends jusqu'a 20s pour arriver a destination je sais pas pourquoi ce retard je vous mets ici le code des deux fichiers:
fichier d envoi :
fichier de reception :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import java.io.*; import java.net.*; public class sd { static final int port = 2057; public static void main(String args[]) throws Exception { if (args.length != 2) { System.out.println("Usage: java UDPSend <hostname> <message>"); System.exit(0); } InetAddress address = InetAddress.getByName(args[0]); byte[] message; message = args[1].getBytes(); System.out.println("lent=" + message.length); DatagramPacket packet = new DatagramPacket(message, message.length,address, port); DatagramSocket socket = new DatagramSocket(); socket.send(packet); socket.close(); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.io.*; import java.net.*; public class rc { static final int port = 2057; public static void main(String args[]) throws Exception { byte[] buffer = new byte[1024]; String s; DatagramSocket socket = new DatagramSocket(port); for( ; ; ) { DatagramPacket packet = new DatagramPacket(buffer, buffer.length); socket.receive(packet); s = new String(buffer,0,packet.getLength()); System.out.println("UDPReceive: received from " + packet.getAddress().getHostName() + ":" +packet.getPort() + ": " + s); } }
plzzzz aidez moi je suis coincé![]()
Partager