java 获取ip的网络号,获取网络上可用的计算机的IP地址? -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

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值