import java.net.Socket; import java.io.IOException; import java.io.InputStream; public class DayTime { public static void main (String args[]) { if (args.length < 1) { System.err.println("Usage: DayTime "); return; } try { Socket sock = new Socket(args[0], 13); InputStream in = sock.getInputStream(); byte[] bytes = new byte[256]; int next_byte = -1; int i=0; while ((next_byte = in.read()) != -1 && (i < bytes.length)) bytes[i++] = (byte) next_byte; sock.close(); int n = i; System.out.println ("\nThe bytes:"); for (i = 0; i < n; i++) System.out.print (bytes[i] + " "); System.out.println ("\n\nBytes as a string:\n" + new String(bytes)); } catch (IOException e) { System.err.println (e); } } }