Created
April 23, 2016 16:23
-
-
Save ejcer/7a453b604be3ab2161cbe0506d091b1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
long startTime = System.currentTimeMillis(); | |
int port = 8000; | |
InetAddress server = InetAddress.getByAddress("8.8.8.8".getBytes()); | |
DatagramSocket socket = new DatagramSocket(port); | |
byte[] buf = new byte[1024]; | |
DatagramPacket ping = new DatagramPacket(buf, buf.length, server, port); | |
try { | |
socket.send(ping); | |
socket.setSoTimeout(1000); | |
DatagramPacket response = new DatagramPacket(new byte[1024], 1024); | |
socket.receive(response); | |
long endTime = System.currentTimeMillis(); | |
pingTimes.add(endTime - startTime); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} catch (UnknownHostException e) { | |
e.printStackTrace(); | |
} catch (SocketException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment