×
Namespaces

Variants
Actions
Revision as of 07:12, 18 June 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Bluetooth chat between two or more devices using J2ME

From Nokia Developer Wiki
Jump to: navigation, search

This Java ME code example uses Bluetooth to establish communication between four devices. The devices all send a message to the server, after which the server displays all the messages on all of the devices. Source code Media:BluetoothChat.zip

Article Metadata
Code ExampleArticle
Created: _katy_ (30 Nov 2009)
Last edited: hamishwillee (18 Jun 2013)

Screenshots (from WTK emulator)

ExplicacaoBlue0.png

Code Explanation

In this example I created six classes: MyMIDlet, BluetoothClient, BluetoothServer, MessageForm, NumberClientesForm and OptionsForm.

The most important classes are: BluetoothClient and BluetoothServer because they are responsible for Bluetooth communication. The BluetoothServer class is responsible for establish connection with all clients and receive a message from each device.

The function createConnections() opens a new Connection and a new DataInputStream for each connected client and the function receiveMessageFromAll() reads all messages sent from other devices.

ExplicacaoBlue1.png

The BluetoothClient class is responsible for searching other devices, establish contact with the server, verify the service number, and then send to the server the user’s message. This class must implement DiscoveryListener class so that it will be able to discover available Bluetooth devices. In this class there is a vector called “devices” where all discovered devices are stored and a List called “deviceList” where I store all discovered device’s name to show later on the screen.

ExplicacaoBlue2.png

This page was last modified on 18 June 2013, at 07:12.
207 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×