Professional Documents
Culture Documents
importjava.io.*;
importjava.net.*;
publicclassUdpClient{
publicstaticvoidmain(String[]args)throwsException{
finalintport=9000;
finalInetAddressaddress=
InetAddress.getByName(args[0]);
DatagramSocketsocket=newDatagramSocket();
Stringinput;
do{
input=readLine()+"\n";
DatagramPacketpacket=new
DatagramPacket(input.getBytes(),input.getBytes().length);
packet.setAddress(address);
packet.setPort(port);
socket.send(packet);
}while(!input.equals(".\n"));
socket.close();
}
publicstaticStringreadLine()throwsException{
returnnewBufferedReader(new
InputStreamReader(System.in)).readLine();
}
}