Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

jsp - get IP addresses of computer available on a network? -java

I am making a file sharing application which would look for computers which are running the application on the same network. So I would like my application to discover computers and their IP address. Is this task achievable using Java?

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is one of the basic problems in distributed computing, and there are two approaches that work, to a degree:

Registry Service

  • Somewhere on the network, you run a Registry Service with a well-known host and port number. This service has to be reachable / addressable from every place you want to run the application.

  • On startup each instance of the application on the network registers itself with the registry.

  • When some machine / program needs to locate an instance of the application, it asks the registry.

Problems:

  • You have to deal with application instances that "go away" without telling the registry.

  • You have to have a way to restore state if the registry restarts.

  • The applications have to know the name (or address) and port of the registry instance.

Broadcast / Multicast

  • Every instance of the application listens on a well-known "broadcast" or "multicast" address / port.

  • When a program wants to locate instances of the application, it sends a broadcast / multicast request.

  • Each instance responds to the request giving its details.

  • The program accumulates the responses to build a list of all "live" instances.

Problems:

  • This doesn't scale. Each and every request from M programs goes to N machines and generates N responses. As M and N grow, the network traffic grows quadratically.

  • Broadcast and Multicast are lossy, especially on busy networks.

  • Broadcast typically doesn't cross network boundaries. Multicast requires special configuration.


Either approach should work on a small network with a limited number of instances.

The simple approach is to identify an existing distributed computing technology that does most of the work for you. For example, RMI and a RMI registry, dynamic DNS, CORBA, JINI.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...