Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Listen for ping messages

 
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?
 
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.
 
What's gotten into you? Could it be this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic