Android 蓝牙聊天示例应用程序 - 多连接 [英] Android Bluetooth Chat sample app - multiple connections

查看:10
本文介绍了Android 蓝牙聊天示例应用程序 - 多连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 Android 蓝牙聊天示例应用程序设置为一次连接多个人,并拥有一个迷你聊天室?这意味着什么?

解决方案

tl;dr version: 蓝牙很糟糕,不要使用它,改用 wifi,可能有网络后端支持.

多年来,为了一个社交无线网络研究项目,我已经彻底调查了这个问题.我的一般建议是:它不适用于超过两个/三个人.蓝牙的设计并没有考虑到无线对等网络.

一般来说,Android 设备(特别是 HTC 的设备,iirc)中包含的廉价蓝牙控制器似乎一次不能真正处理超过两个或三个连接.我不确定这是硬件还是固件问题,但我可以讲述一些基本的轶事.我在 2011 年初左右在 SDK 级别(即,没有修改固件)努力实现这个想法,并且能够让对等点获得两个额外的连接(即三个设备,每个连接到另外两个)到工作几分钟到一个小时,然后连接突然中断,套接字将变得无法使用,需要重新连接.不幸的是,20 分钟是一个上限,通常不可能可靠地连接到多个一个其他设备.

该项目的目标是支持多人在后台静默互动,但这从未实现,相反,我们放弃了蓝牙,转而使用 wifi,效果更好.概括地说,我认为人们将蓝牙视为可靠的点对点通信的一种可能媒介,但它的真正设计方式并非如此:它更像是一种用于小型设备(想想耳机)之间短距离通信的媒介.

请注意,如果您想这样做,您可以连接的最大设备数量是固定的,因为根据蓝牙规范,一个微微网最多支持七个设备.(请参阅维基百科文章.)

所需的更改很简单:您为每个设备使用不同的 UUID.这可以通过多种方式实现,使用带外交换机制,或以递增方式分配 UUID 的简单方案,并在连接到网络时,依次尝试每种方式.

以下是一些相关的 Google 群组话题:

我记得发布了一篇更详细的文章,详细说明了如何做到这一点(使用代码),如果我能找到的话,我也可以挖掘它.应该是 2010 年末或 2011 年初.

所以答案是,抽象地说,是的,您可以尝试通过使用多个 UUID 来做到这一点(在您使用一个之后,就是这样,您必须使用一些分配尝试另一个协议).然而,在实践中,经过大量的反复试验,这对于您可能想要使用它的目的并不真正有效,而是使用互联网后端更好很多.顺便说一句,这也很好,还有另一个原因,大多数用户真的不喜欢打开蓝牙,因为担心电池耗尽..

Is it possible to set up the Android Bluetooth Chat sample app to connect more than one person at a time, and have a mini chat room? What would that entail?

解决方案

tl;dr version: Bluetooth sucks for this, don't use it, use wifi instead, probably backed by a web backend.

I have investigated this issue thoroughly throughout the years in the interests of a social wireless network research project. My general advice is: it doesn't work with more than two / three people. Bluetooth just isn't designed with wireless peer to peer networks in mind.

In general, it seems that the cheap Bluetooth controllers included on Android devices (especially HTC's devices, iirc) don't really handle any more than two or three connections at a time. I'm unsure if this is a hardware or firmware problem, but I can recount some basic anecdotes. I was working to implement this idea at the SDK level (i.e., without firmware modifications) around the beginning of 2011, and was able to get a peer to get two additional connections (i.e., three devices, each connecting to the other two) to work for a period of a few minutes to an hour before the connections would suddenly die and the socket would become unusable, requiring reconnection. Unfortunately, 20 minutes was an upper bound, and generally it was impossible to get connections to more than one other device at all reliably.

The goal of the project was to support multiple people interacting with each other silently in the background, but this never materialized, instead we ditched Bluetooth and went with wifi instead, which worked much much better. In the abstract, I think people view Bluetooth as a possible medium for reliable peer to peer communication, but it wasn't really designed that way: it's more of a medium used for short range communication between small devices (think headsets).

Be aware that if you want to do this, the maximum number of devices to which you can connect is fixed, because as per the Bluetooth spec, a piconet supports a maximum of seven devices. (See the wikipedia article.)

The required change is simple: you use a different UUID for each device. This can be implemented a number of ways, using an out of band exchange mechanism, or simple scheme where you assign UUIDs in an increasing fashion and when connecting to the network, try each in succession.

Here are some relevant Google groups threads:

I remember posting a more elaborate one detailing how to do this (with code) that I might dig up as well.., if I can find it. It should be from late 2010 or early 2011.

So the answer is, in the abstract, yes, you can try to do this, by using multiple UUIDs (after you use one, that's it, and you have to try another using some assignment protocol). However, in practice, after a lot of trial and error, this doesn't really work for what you probably want to use it for, and it's a lot better to go with an internet backend instead. By the way, this is also good for another reason, most users don't really like to turn on their Bluetooth for fear of their battery being drained..

这篇关于Android 蓝牙聊天示例应用程序 - 多连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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