Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listen for ping messages

 
Rishabh Gogia
Greenhorn
Posts: 4
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I listen for ping commands. Another machine will try to ping mine and I must detect it in my application and display a message to the user. Is there any predefined API that I can use? Or how do i go on writing the code on my own?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're talking about the actual ICMP protocol used by the ping command, you can't do it in pure Java, as that is a network layer protocol and Java's built-in networking API only goes down to the transport layer.

If you're using "ping" in a more generic sense, such as "heartbeat," that is, "the other host has to send some small packet and I have to respond with a small packet," then you can implement that however you want. You could listen on a particular socket for a TCP connection, or you could just listen for UDP packets. Other than that, any details about how you implement it would depend on your specific requirements and constraints.
 
Rishabh Gogia
Greenhorn
Posts: 4
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i need to listen to ICMP ping messages coming from another machine. I found out that Jpcap can be used for this purpose. Is this possible? Any good tutorials for using Jpcap?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rishabh Gogia wrote:hi, i need to listen to ICMP ping messages coming from another machine. I found out that Jpcap can be used for this purpose. Is this possible?


Yeah, it's possible, but it's not pretty.

Any good tutorials for using Jpcap?


Not that I know of. Last time I had to do something like this, another developer on my team handled the native side of things. I would just try googling for something like jpcap ping example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic