This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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.
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!