V
V
Vitaly2016-10-22 23:52:09
Java
Vitaly, 2016-10-22 23:52:09

Java Server Ping?

Tell me how to get the delay from the server? I'm making a JavaFX application that displays pings from 10 servers.
At the moment this is executing the code:

public String getPing(){
        try {
            String ipAddress = ipAdress;
            InetAddress inet = InetAddress.getByName(ipAddress);

            long finish = 0;
            long start = new GregorianCalendar().getTimeInMillis();

            if (inet.isReachable(5000)){
                finish = new GregorianCalendar().getTimeInMillis();
                return  (finish - start + " ms");
            } else {
                return  " Сервер не доступен.";
            }
        } catch ( Exception e ) {
            System.out.println("Exception:" + e.getMessage());
        }
        return "No connect";
    }

I found a simple solution in C#:
label2.Text = new Ping().Send("www.google.ru").RoundtripTime.ToString() + "ms";

ps In Java, everything is written with big problems (Perhaps because I just started, but I try to write in several languages ​​and compare them.)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question