Ping.java


Below is the syntax highlighted version of Ping.java from §8.4 Operating Systems.



/******************************************************************************
 *  Compilation:  javac Ping.java
 *  Execution:    java Ping host
 *
 ******************************************************************************/

import java.io.*;
import java.net.*;

public class Ping {
    public static void main(String[] args) throws Exception {
        String hostname = args[0];
        int port = 13;                     // daytime port


        Socket socket = new Socket(hostname, port);
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String time = br.readLine();
        StdOut.println("time = " + time + " on machine " + hostname);

    }
}


Copyright © 2000–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:33:43 EDT 2022.