获取所有本地ip(arp -a) [英] getting all local ip's (arp -a)

查看:333
本文介绍了获取所有本地ip(arp -a)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个不错的多人游戏应用程序,但是我希望我的应用程序搜索您局域网中的主机.我知道您可以很容易地获得自己的IP,然后强行强制所有IP来查看是否已连接任何东西,但这对您的计算机来说是很辛苦的工作,即使正确地对其进行多线程处理,也要花费一些时间.

在Java中似乎没有很好的方法来获取arp表,但我希望有类似的方法可以快速高效地获取所有本地IP地址.

任何帮助将不胜感激.

解决方案

存在多个选项,可用于实现此目的.

去中心化的人

您可以做的是 广播 来自您的应用程序的请求,该请求会询问网络上的每个主机当前是否可用于游戏(例如,在255.255.255.255上发送请求,将导致路由器重新发送您发送到LAN上每个主机的数据报).

这将确保只有已启动游戏并准备好进行游戏的主机才能响应此请求.

如今,LAN上大量使用了几种广播协议.其中之一是 SSDP(简单服务发现协议),它与UPnP协议一起用于服务发现.当然,对于多人游戏,肯定有更好的广播/多播协议.

集中式

在多人游戏中发现玩家的最常见方法之一仍然是中央服务器,该服务器上既有请求者(正在寻找游戏的人)又是托管者(主持游戏的人)已连接.

此方法的缺点是具有单一故障点(即服务器),但与分散式解决方案不同,它具有既适用于LAN又适用于Internet(或每个基于IP的协议)的优点. /p>

如果我必须开发多人游戏,那么我将在这里开始研究您需要实现的主机发现功能.

I am making a nice multiplayer application but I want my application to search for hosts in you lan. I know that you can obtain your own IP quite easily and then brute force all IPs to see if anything is connected, but this is both quite hard work for your computer and it takes a some time as well even when you multithread it properly.

There seems to be no good way to obtain the arp table in java but I hope there is something similar where you can obtain all local IP-addresses fast and efficient.

Any help would be much appreciated.

解决方案

Several options exists and can be used to achieve this.

The decentralized one

What you could do is broadcasting a request from your application that asks every hosts on the network if they are currently available for a game (sending the request on 255.255.255.255 for instance, will cause your router to retransmit the datagrams you sent to every host on a LAN).

This will ensure that only the hosts that have the game launched and which are ready to play will respond to this request.

Several broadcasting protocols are today heavily used on a LAN. One of them is SSDP (Simple Service Discovery Protocol) which is used with the UPnP protocol for service discovery. There are certainly better suited protocols used over broadcast/multicast for multiplayer games though.

The centralized one

One of the commonest way to discover players on a multiplayer game remains in the presence of a central server on which both requester (people who are looking for a game) and hosters (people who are hosting a game) are connected.

This method has the disadvantage of having a single point of failure, which is the server, but has the advantage, unlike the decentralized solution, of being both suitable for a LAN and for Internet (or every IP based protocol).

If I had to develop a multiplayer game this is where I would start digging regarding the host discovery feature you are required to implement.

这篇关于获取所有本地ip(arp -a)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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