Namespaces
Variants
Actions

Bluetooth chat between two or more devices using J2ME

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 Example
Article
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.
358 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved