Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adapting Android Bluetooth Chat for multiple devices

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.

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

like image 684
Megh Avatar asked Oct 15 '22 05:10

Megh


1 Answers

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.

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!

like image 70
Ryan Hayes Avatar answered Oct 18 '22 22:10

Ryan Hayes