aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Listen for ping messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Listen for ping messages" Watch "Listen for ping messages" New topic
Author

Listen for ping messages

Rishabh Gogia
Greenhorn

Joined: Jan 17, 2012
Posts: 4

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Jan 17, 2012
Posts: 4

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Listen for ping messages