获取网络上可用的计算机的IP地址? -java [英] get IP addresses of computer available on a network? -java

查看:274
本文介绍了获取网络上可用的计算机的IP地址? -java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个文件共享应用程序,寻找在同一网络上运行应用程序的计算机。所以我想我的应用程序发现计算机及其IP地址。使用Java可以实现这个任务吗?



感谢

解决方案

分布式计算的一个基本问题,有两种方法可以在一定程度上起作用:



注册服务




  • 在网络上的某个地方,您使用知名的主机和端口号运行注册表服务。


  • 在启动时,网络上的每个应用程序实例都会注册自己的应用程序注册表。


  • 当某些计算机/程序需要定位应用程序的实例时,会询问注册表。




问题:




  • 您必须处理应用程式执行个体


  • 如果注册表重新启动,您必须有恢复状态的方法。


  • 应用程序必须知道注册表实例的名称(或地址)和端口。




广播/多播




  • 应用程序的每个实例都侦听着名的广播 地址/端口。


  • 当程序想要查找应用程序的实例时,它会发送广播/组播请求。


  • 程序累积响应以构建一个列出所有活动实例。




问题:




  • 这不会缩放。来自M个程序的每个请求到达N个机器并且生成N个响应。


  • 广播和组播是有损耗的,特别是在繁忙的网络。


  • 广播通常不跨越网络边界。多播需要特殊配置。









简单的方法是识别现有的分布式计算技术,为您完成大部分工作。例如,RMI和RMI注册表,动态DNS,CORBA,JINI。


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.

这篇关于获取网络上可用的计算机的IP地址? -java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆