Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 04: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 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

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

Screenshots (from WTK emulator)


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.


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.


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