It's not a secret anymore!*
The moose likes Sockets and Internet Protocols and the fly likes Pinging a whole network and getting answers from listening servers 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 "Pinging a whole network and getting answers from listening servers" Watch "Pinging a whole network and getting answers from listening servers" New topic
Author

Pinging a whole network and getting answers from listening servers

Andreas Pax Lück
Greenhorn

Joined: Nov 04, 2009
Posts: 18
Hi friends!

I searched the internet about my problem, but didn't really find satisfying answers. This thread seemed to be interesting: http://www.coderanch.com/t/209321/Distributed-Java/java/there-any-method-get-address

I have to develop a kind of server application which does listen, among other things, for ping requests and answer to the specific machine. This client machine doesn't know the IP address. So I tried to ping to 255.255.255.255 but this IP was rejected. Is there any way to send a request to all participants without the knowledge of their IPs?


Best regards


PAX


"Wenn man irgendwann mal von allen akzeptiert wird, dann weiß man, dass man irgendwas falsch gemacht hat."
Excerpt by: Mr. Weidner
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Perhaps DatagramSockets are what you need. These allow you to multicast messages.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Andreas Pax Lück
Greenhorn

Joined: Nov 04, 2009
Posts: 18
Hi Rob.

Thanks for your answer. I'd like to excuse my belated reply, I was a bit busy in the previous weeks.

I informed me about this multicast communication. The key note is that this connectionless kind of communication provides the possiblity that participants join any group and every message which is sent to this group will be obtained by every group member. A group is defined by a class D network IP address.

I think, this approach would solve my concern. But I've got a question: The group is defined by a class D address. If another (further) application uses the same IP in any way, does my application produce any conflicts?

I implemented a ping prototype which does only work localy. This means, if the client and the server are running on the same machine, the ping request arrives the server. But if there's a further server on the network running on another machine, no ping comes in.

This is the client's ping:


And here's the server:


As already mentioned, it does only work if server and client are running on the same computer. The computers are connected via a router on my network. The client code for the listening to answers isn't shown in the code above. First, it starts the listener in a separate thread and then it sends the ping.

Do you know what's wrong with my solution?

Best regards


PAX
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pinging a whole network and getting answers from listening servers