How do u ping in java

Questions by ikprasanth   answers by ikprasanth

Showing Answers 1 - 6 of 6 Answers

Anirban Kundu

  • Oct 3rd, 2006
 

Java's support for UDP is using java.net.DatagramSocket and java.net.DatagramPacket. You may try these classes for implementing ping functionality. UDP is connectionless protocol and (think) ping is built on top of it. Try this website for more details.

http://www.cafeaulait.org/course/week12/36.html

  Was this answer useful?  Yes

nencho lupanov

  • Oct 18th, 2006
 

ping has nothing to do with udp - it is network level protocol

  Was this answer useful?  Yes

Guest

  • Jan 9th, 2007
 

Ping is based on the ICMP protocol and has nothing with UDP.

  Was this answer useful?  Yes

me

  • Feb 5th, 2007
 

Ping is based on ICMP. Java has no support for this. They have UDP and TCP sockets. In Java 5 there is an isAlive call that says if a host is alive or not, but is not a ping. You could do the same thing with a TCP socket to a known open port.If you want ping in Java you could download one of the hard to find libraries that does it (some are not free) or you could use JNI to write a simple ping in C in a few seconds and just call the native method from your Java wrapper. That is not truly a Java solution due to having to distribute natively compiled libraries along with your classes, but that is currently the only solution in Java for true ping functionality.

  Was this answer useful?  Yes

Its quite simple.

You need to do this two steps.

First send Packet with seq=0 ack=0 flag=1 and data 1
Then wait until the server confirms you this packet, that mean wait until you receive the packet (0,0,1,{1})
When you receive that packet you have just pinged the server and now you can send/recieve data.

When the server receive the 0,0,1,1 packet it also gives you id on which you two will communicate.

Sorry for my English, hope it helps

There is a log of my implementation of UDP in java


Code
  1. span style="color: #666666; font-style: italic;">/***.***.***.***:***

  2. 2012-04-14 21:31:28,858 DEBUG | Robot $ : Robot -> UDP -> should be connected now

  3. 2012-04-14 21:31:28,858 DEBUG | Robot $ : Robot -> UDP -> unleasing work

  4. 2012-04-14 21:31:28,859 INFO  | UDP   $ : Start recieving

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions