FileDocCategorySizeDatePackage
DaytimeObject.javaAPI DocExample1265Sat Oct 26 09:53:50 BST 2002None

DaytimeObject

public class DaytimeObject extends Object
DaytimeObject - connect to the non-standard Time (object) service.
author
Ian F. Darwin
version
$Id: DaytimeObject.java,v 1.4 2002/10/26 13:53:50 ian Exp $

Fields Summary
public static final short
TIME_PORT
The TCP port for the object time service.
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)


	     
		String hostName;
		if (argv.length == 0)
			hostName = "localhost";
		else
			hostName = argv[0];

		try {
			Socket sock = new Socket(hostName, TIME_PORT);
			ObjectInputStream is = new ObjectInputStream(new 
				BufferedInputStream(sock.getInputStream()));

			// Read and validate the Object
			Object o = is.readObject();
			if (o == null) {
				System.err.println("Read null from server!");
			} else if ((o instanceof Date)) {

				// Valid, so cast to Date, and print
				Date d = (Date) o;
				System.out.println("Server host is " + hostName);
				System.out.println("Time there is " + d.toString());

			} else {
				throw new IllegalArgumentException("Wanted Date, got " + o);
			}
		} catch (ClassNotFoundException e) {
			System.err.println("Wanted date, got INVALID CLASS (" + e + ")");
		} catch (IOException e) {
			System.err.println(e);
		}