-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathClientEcho.java
More file actions
25 lines (20 loc) · 875 Bytes
/
ClientEcho.java
File metadata and controls
25 lines (20 loc) · 875 Bytes
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 ClientEcho
{
final static int taille = 1024;
final static byte buffer[] = new byte[taille];
public static void main(String argv[]) throws Exception
{
InetAddress serveur = InetAddress.getByName(argv[0]);
int length = argv[1].length();
byte buffer[] = argv[1].getBytes();
DatagramPacket dataSent = new DatagramPacket(buffer,length,serveur,ServeurEcho.port);
DatagramSocket socket = new DatagramSocket();
socket.send(dataSent);
DatagramPacket dataRecieved = new DatagramPacket(new byte[length],length);
socket.receive(dataRecieved);
System.out.println("Data recieved : " + new String(dataRecieved.getData()));
System.out.println("From : " + dataRecieved.getAddress() + ":" + dataRecieved.getPort());
}
}