*
The moose likes Sockets and Internet Protocols and the fly likes Java Ping and RTT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Java Ping and RTT" Watch "Java Ping and RTT" New topic
Author

Java Ping and RTT

subham soni
Greenhorn

Joined: Jun 30, 2013
Posts: 3
I need to write the TCP socket program client-server architecture for ping command and also determine the Round Trip Time of the Host connected too.. I can ping the host by isReachable() method but what to do about RTT? please help
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18534
    
  40

subham soni wrote:I need to write the TCP socket program client-server architecture for ping command and also determine the Round Trip Time of the Host connected too.. I can ping the host by isReachable() method but what to do about RTT? please help



I don't think that there is a way to calculate RTT from one host, to any random host. Pinging another host works because there is a standard service -- and even then, it isn't guaranteed to work reliably. If you want to calculate RTT, you will need to install agents on the remote host (either something you write, or just install, if you find some sort of service).


Regardless, it isn't had to do (if you want to write it yourself). To calculate RTT, you need a pinger and ponger. The ponger is just a reflector (running on the remote host) -- that just bounces the same packet back. And as for the pinger, it just takes a time stamp, sends a packet to the ponger, gets the response, takes another time stamp; and if the returned packet is confirmed to be the same packet, the RTT is the difference between the two timestamps.


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
subham soni
Greenhorn

Joined: Jun 30, 2013
Posts: 3
Ok to be frank I need to write java program(sockets) to implement the ping command
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18534
    
  40

subham soni wrote:Ok to be frank I need to write java program(sockets) to implement the ping command


The nice thing here is that you don't need to worry about writing the ping program. Once you write the RTT program(s), ping is done. If you can get an RTT, then it is there. Of course, you have to modify the RTT program with a timeout, which you have to do for error handling anyway.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Ping and RTT
 
Similar Threads
status of internet connection
Unknown SMTP host for gmail
How to read a html page from internet.
SQL Server 2005 Connection using SQL Explorer 3.5 in Eclipse
Major problems with networking client.