适应Android的蓝牙聊天多个设备 [英] Adapting Android Bluetooth Chat for multiple devices

查看:191
本文介绍了适应Android的蓝牙聊天多个设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做蓝牙学院项目为Android,和我想要了解如何管理多个连接设备之间的通信。最后,我要开发一个多人蓝牙游戏。

I'm doing a college project on Bluetooth for Android, and I'm trying to understand how to manage communication between multiple connected devices. Eventually I'm going to develop a multiplayer Bluetooth Game.

目前我已经适应Android的示例应用程序BluetoothChat连接我的三个盈置One手机。 1连接到2谁连接到3 1发送它的消息成功为2 3发送其消息成功地2为好。 2可以成功地发送其消息1和3中,作为这股ConnectedThread与两者。但我无法弄清楚如何处理从1至3获得通信

Currently I've adapted Android's sample app BluetoothChat to connect my three Nexxus One phones. 1 connects to 2 who connects to 3 1 sends its messages successfully to 2. 3 sends its messages successfully to 2 as well. 2 can send its messages successfully to 1 and 3, as it shares a ConnectedThread with both. But I can't figure out how to handle getting communication from 1 to 3.

有没有人有多个设备之间的通信的任何实例或已经这样做了自己呢?谢谢

Does anyone have any examples of communication between multiple devices or has done this themselves? Thanks

推荐答案

一种方法是与发送者和接收者注释您的信息,这样当2得到消息,它知道在交付给3.当3变一个消息,它会检查接收器属性,知道它是从装置1。这额外的一层,您可以通过其他设备发送和接收消息并仍然能够知道它是谁。

One way is to annotate your messages with the sender and receiver, so that when 2 gets the message, it knows to deliver it on to 3. When 3 gets a message, it checks the receiver attribute to know it is from device 1. This extra layer allows you to send and receive messages through other devices and still be able to know who it is from.

不过,首先你需要弄清楚如何让每一个设备了解网络上的其他设备。如果你只是连接在一条线上,像1-2-3-4,那么每一个设备进入网络时,你可以通过网络发送一个更新的列表,但如果2滴发生了什么?你刚才退出游戏?等待它重新配对?在这种情况下,它可能是更好看一个的对等体的网络,或者你让一个设备是主机,特别是如果这是为了以后可以多人游戏的典型的客户服务器结构。
希望帮助!

First, though, you'll need to figure out how to make every device know about every other device on the network. If you're just connecting in a line, like 1-2-3-4, then every time a device enters the network, you could send an updated list through the network, but what happens if 2 drops out? Do you just quit the game? Wait for it to be re-paired? In this case, it may be better to look at a peer-to-peer network, or the typical client server architecture where you let one device be the host, especially if this is intended to later be a multiplayer game.
Hope that helps!

这篇关于适应Android的蓝牙聊天多个设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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