//: udpClient0.java // SYNOPSIS: udpClient0 // DESCRIPTION: The program creates a datagram socket in the inet // domain, send the message "HI" to udpServer0 running at // at port 12345 and exits //////////////////////////////////////////////////////////////////////// import java.net.*; import java.io.*; public class udpClient0 { public static void main(String[] args) throws IOException { if (args.length != 1) { System.out.println("Usage: java udpClient0 HostName"); System.exit(0); } // Connect to machine provided InetAddress addr = InetAddress.getByName(args[0]); // Create a udp socket. DatagramSocket socket = new DatagramSocket(); // Guard everything in a try-finally to make // sure that the socket is closed: try { System.out.println("Sending the udp socket..."); // Send the Message "HI" socket.send(Dgram.toDatagram("HI",addr,12345)); // or socket.send(Dgram.toDatagram("HI",addr,udpServer0.INPORT)); } finally { // System.out.println("closing the socket..."); socket.close(); } } } ///:~