import java.net.*;
import java.io.*;

public class DateClient {

    private static final String HOST_NAME  = "localhost";
    private static final int PORT_NUMBER = 8899;

    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket();
        byte[] buf = new byte[256]; // prepare empty packet
        InetAddress address = InetAddress.getByName(HOST_NAME);
        DatagramPacket packet =
                new DatagramPacket(buf, buf.length, address, PORT_NUMBER);
        socket.send(packet);        // send packet to server
        packet = new DatagramPacket(buf, buf.length);
        socket.receive(packet);     // wait for packet from server
        int len = packet.getLength();
		String received = new String(packet.getData()).substring(0,len); // extract date
        System.out.println("date received: " + received);
        socket.close();
    }
}
