API 14日之前Android的网络搜索服务(ISH) [英] Android Network Discovery Service (ish) before API 14

查看:112
本文介绍了API 14日之前Android的网络搜索服务(ISH)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够发现本地网络上的服务(所以说我正在运行的聊天应用程序,我想探索运行此聊天的本地网络中的其他设备),但遗憾的是我需要能够使用它与API&LT装置; 16(所以我不能使用android.net.nsd),我相信这可以在不使用NSD API来完成。问题是如何。任何帮助?

I need to be able to discover the services on the local network (so say I am running a chat application and I want to discover other devices on local network running this chat), but sadly I need to be able to use it on devices with API < 16 (so I cannot use android.net.nsd) I am sure this can be done without using NSD API. Question is how. Any help?

推荐答案

有至少三个或四个选项。

There are at least three or four options.

您可以使用

TCP或UDP

  1. 广播地址
  2. 组播地址
  3. 在遍历所有不会忽略你的网络中

HTTP

4。利用外部服务器或类似的东西GCM的(谷歌云消息传递)

4 Make use of external server or something like GCM (Google Cloud Messaging)

ad.1和2

优点:

+易于实施,服务器发送predefined上特定端口的子网/网络广播/多播地址Hello消息,客户端侦听的端口上,当Hello消息到来时,他不由自主地知道服务器的IP地址(包含在包)

+Easy to implement, server is sending predefined "hello" message on broadcast/multicast address of your subnet/network on specific port, client is listening on that port and when "hello" message arrives, he automatically knows server IP address (contained in packet)

+无需连接到互联网

缺点:

  • 在一些公共网络块这个地址以躲避攻击(如​​洪水)。

广告3。

优点:

在多播和广播被阻止什么,你所能做的就是简单地遍历整个子网。这是暴力破解的方法,但工作,特别是在典型的家庭/小型网络,其中掩码是/ 24 - 有遍历仅255地址。

When Multicast and Broadcast is blocked what you can do is simply iterate over whole subnet. It is " brute force " method, but works, especially on typical home/small networks where mask is /24 - there are only 255 addresses to iterate through.

连接到互联网也无需

缺点

当面膜让说/ 16将采取pretty的太多的时间来遍历所有IP

When mask is let say /16 it will take pretty much time to iterate all IPs

可能会导致电池消耗

和将淹没网络。

广告。 4

另一种方法是将一些外部服务器,这将是方位点的设备。他们每个人都发了自己的地址,并期待如果有来自同一个网络中的另一设备的一些条目。

Another approach is to make some external server that will be "orientation point" for devices. Each of them sends up its own Address, and looks if there are some entries from another devices from the same network.

是必要的,当然互联网连接。

Of course Internet connection is needed.

所以,我认为这是开始广播和多播,因为它是非常简单的,并会在很多地方,但要记住,有网络的地方是不允许使用的好主意。

So, I think it is good idea to start with broadcast and multicast since it is very simply and will work in many places, but keep in mind that there are networks where it is not allowed to use.

很好的参考可以在这里<一个发现href="http://docs.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html">http://docs.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html

您也应该检查这一个<一个href="http://home.heeere.com/tech-androidjmdns.html">http://home.heeere.com/tech-androidjmdns.html

这篇关于API 14日之前Android的网络搜索服务(ISH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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