PC Connectivity over Bluetooth in Java Applications - Simple and Chat examples

--------------------------------------------------------------------------------

 

These Java™ code examples demonstrate Bluetooth serial port communication

between a PC and a mobile device. The package is divided into PC software (run from

Java main method) and device software (MIDlets), which both have the same directory structure

and applications:

1) Simple examples to set up a Bluetooth serial port profile client or server;

2) Chat application, which forms a Bluetooth point-to-point network (note that

some Bluetooth devices do not support point-to-multipoint connections).

 

--------------------------------------------------------------------------------

 

PREREQUISITES

 

 

MIDP 2.0 basics and knowledge of the JSR-82 mandatory part (javax.bluetooth).

Basic knowledge of Java programming language is mandatory.

 

--------------------------------------------------------------------------------

 

SOFTWARE DEPENDENCIES

 

To run the example applications in a PC you need to install

BlueCove (http://sourceforge.net/projects/bluecove/).

 

To connect from a PC through the Virtual COM port to your device you need to use

serial port software. The Java Communications API (also known as javax.comm)

provides a SerialDemo application (http://java.sun.com/products/javacomm/).

 

--------------------------------------------------------------------------------

 

FILES

 

./DeviceSoftware

./DeviceSoftware/.classpath

./DeviceSoftware/.project

./DeviceSoftware/ChatMIDlet.jad

./DeviceSoftware/ChatMIDlet.jar

./DeviceSoftware/SimpleMIDlet.jad

./DeviceSoftware/SimpleMIDlet.jar

./DeviceSoftware/src

./DeviceSoftware/src/chat

./DeviceSoftware/src/chat/BluetoothSettings.java

./DeviceSoftware/src/chat/ChatApplication.java

./DeviceSoftware/src/chat/ConnectionProtocol.java

./DeviceSoftware/src/chat/DiscoveryThread.java

./DeviceSoftware/src/chat/LcduiUI.java

./DeviceSoftware/src/chat/Log.java

./DeviceSoftware/src/chat/ServerThread.java

./DeviceSoftware/src/chat/WorkaroundStreamConnection.java

./DeviceSoftware/src/simple

./DeviceSoftware/src/simple/DeviceClientCOMM.java

./DeviceSoftware/src/simple/DeviceServerCOMM.java

./PCSoftware

./PCSoftware/.classpath

./PCSoftware/.project

./PCSoftware/build.xml

./PCSoftware/lib

./PCSoftware/lib/DOWNLOAD_BLUECOVE.txt

./PCSoftware/src

./PCSoftware/src/chat

./PCSoftware/src/chat/BluetoothSettings.java

./PCSoftware/src/chat/ChatApplication.java

./PCSoftware/src/chat/ConnectionProtocol.java

./PCSoftware/src/chat/DiscoveryThread.java

./PCSoftware/src/chat/Log.java

./PCSoftware/src/chat/ServerThread.java

./PCSoftware/src/chat/SwingUI.java

./PCSoftware/src/chat/WorkaroundStreamConnection.java

./PCSoftware/src/simple

./PCSoftware/src/simple/PCClientCOMM.java

./PCSoftware/src/simple/PCServerCOMM.java

./README.txt

 

 

 

--------------------------------------------------------------------------------

 

KNOWN ISSUES

 

 

The simple examples in the device side append text output to the LCDUI form, which may

crash if run endlessly.

 

S60 2nd Edition; S60 2nd Edition, Feature Pack 1; and Series 80 2nd Edition devices:

Using Bluetooth serial port (RFCOMM) connection is not recommended due to disconnection

issue (this should not apply to S60 2nd Edition, Feature Pack 2, and newer devices).

For further information, see known issue KIJ000109 in the Forum Nokia technical library:   http://www.forum.nokia.com/Technical_Library/FNTL/Using_Bluetooth_serial_port_in_MIDlets.htm.

 

 

BlueCove's method to request a friendly name of the remote device may crash.

 

 

--------------------------------------------------------------------------------

 

RUNNING THE PC SOFTWARE

 

All PC software can be run from Eclipse once BlueCove is set up to your

system and you have changed the project properties accordingly to your

BlueCove installation. Of course you may also run the examples from the command

line. In this case, remember to add the BlueCove Java archive to your classpath

argument. An Ant build script is provided as well.

 

 

Simple Server

~~~~~~~~~~~~~

 

File:

 

    PCSoftware/src/simple/client/PCServerCOMM.java

 

Running from commandLine:

 

    java -cp bin;lib\bluecove.jar example.simple.client.PCServerCOMM

 

Running with Ant:

 

    ant run-server

 

       

Simple Client

~~~~~~~~~~~~~

 

File:

 

    PCSoftware/src/simple/client/PCClientCOMM.java

 

Running from commandLine:

 

    java -cp bin;lib\bluecove.jar example.simple.client.PCClientCOMM

   

Running with Ant:

 

    ant run-client

 

 

Chat Application

~~~~~~~~~~~~~~~~

 

Files:

 

    PCSoftware/src/chat/BluetoothSettings.java

    PCSoftware/src/chat/ChatApplication.java

    PCSoftware/src/chat/ConnectionProtocol.java

    PCSoftware/src/chat/DiscoveryThread.java

    PCSoftware/src/chat/Log.java

    PCSoftware/src/chat/ServerThread.java

    PCSoftware/src/chat/SwingUI.java

      

Running from commandLine:

 

    java -cp bin;lib\bluecove.jar example.chat.ChatApplication

 

Running with Ant:

 

    ant run

 

--------------------------------------------------------------------------------

 

RUNNING THE DEVICE SOFTWARE

 

 

All device software can be run as MIDlets in your device. Refer to your

device manual for instructions on how to deploy the MIDlet into your device. Deployed MIDlets

can be run as applications.

 

Simple Server

~~~~~~~~~~~~~

 

Files:

 

    DeviceSoftware/src/simple/client/DeviceServerCOMM.java

    DeviceSoftware/SimpleMIDlet.jad

    DeviceSoftware/SimpleMIDlet.jar

 

   

Simple Client

~~~~~~~~~~~~~

 

Files:

 

    DeviceSoftware/src/simple/client/DeviceClientCOMM.java

    DeviceSoftware/SimpleMIDlet.jad

    DeviceSoftware/SimpleMIDlet.jar

   

Chat Application

~~~~~~~~~~~~~~~~

 

Files:

 

    DeviceSoftware/src/chat/BluetoothSettings.java

    DeviceSoftware/src/chat/ChatApplication.java

    DeviceSoftware/src/chat/ConnectionProtocol.java

    DeviceSoftware/src/chat/DiscoveryThread.java

    DeviceSoftware/src/chat/Log.java

    DeviceSoftware/src/chat/ServerThread.java

    DeviceSoftware/src/chat/SwingUI.java

    DeviceSoftware/ChatMIDlet.jad

    DeviceSoftware/ChatMIDlet.jar

 

 

 

--------------------------------------------------------------------------------

 

COMPATIBILITY

 

S60 2nd Edition

S60 3rd Edition

(Series 40 2nd Edition)

(Series 40 3rd Edition)

 

The example MIDlets have been tested on the Nokia 6630 and Nokia E70 mobile devices. The example Java applications has been tested on Windows XP SP2 with

BlueCove version 1.1.2 and EPoX BT-DG03 Bluetooth USB Dongle.

--------------------------------------------------------------------------------   

 

EVALUATE THIS RESOURCE

 

Please spare a moment to help us improve documentation quality and recognize the examples you find most valuable, by rating this resource.