获取网络上可用计算机的 IP 地址?

编程入门 行业动态 更新时间:2024-10-28 09:24:56
本文介绍了获取网络上可用计算机的 IP 地址?-java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在制作一个文件共享应用程序,它将查找在同一网络上运行该应用程序的计算机.所以我希望我的应用程序能够发现计算机及其 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?

谢谢

推荐答案

这是分布式计算中的基本问题之一,在某种程度上有两种方法可以解决:

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

  • 在网络上的某个地方,您运行着具有众所周知的主机和端口号的注册服务.此服务必须可从您要运行应用程序的每个位置访问/寻址.

  • 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.

问题:

  • 您必须在不通知注册表的情况下处理消失"的应用程序实例.

  • 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.

  • 应用程序的每个实例都侦听众所周知的广播"或多播"地址/端口.

  • 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.

问题:

  • 这不能扩展.来自 M 个程序的每个请求都发送到 N 台机器并生成 N 个响应.随着 M 和 N 的增长,网络流量呈二次增长.

  • 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.

简单的方法是确定一种现有的分布式计算技术,它可以为您完成大部分工作.例如,RMI 和 RMI 注册中心、动态 DNS、CORBA、JINI.

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 地址?

本文发布于:2023-06-08 15:36:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/583972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地址   计算机   网络   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!