hi folks,
i want to develop a desktop application which will continuously receive text commands from a connected mobile device, via bluetooth rfcomm protocol.
i went through hundreds of code examples, including jsr-82 bluetooth & obex api demos; but cannot get what i wanted.
one of the popular examples that i am trying to deal with is here;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.bluetooth.*;
import javax.microedition.io.*;
/**
* Class that implements an SPP Server which accepts single line of
* message from an SPP client and sends a single line of response to the client.
*/
public class SampleSPPServer {
//private static LocalDevice localDevice;
static LocalDevice localDevice;
DiscoveryAgent agent;
//start server
private void startServer() throws IOException{
//Create a UUID for SPP
UUID uuid = new UUID(0x1101);
//Create the servicve url
String connectionString = "btspp://localhost:" + uuid +";name=SampleSPPServer";
//open server url
StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open( connectionString );
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
StreamConnection connection=streamConnNotifier.acceptAndOpen();
RemoteDevice dev = RemoteDevice.getRemoteDevice(connection);
System.out.println("Remote device address: "+dev.getBluetoothAddress());
System.out.println("Remote device name: "+dev.getFriendlyName(true));
//read string from spp client
InputStream inStream=connection.openInputStream();
BufferedReader bReader=new BufferedReader(new InputStreamReader(inStream));
String lineRead=bReader.readLine();
System.out.println(lineRead);
}
public static void main(String[] args) {
//display local device address and name
try{
localDevice = LocalDevice.getLocalDevice();
System.out.println("Address: "+localDevice.getBluetoothAddress());
System.out.println("Name: "+localDevice.getFriendlyName());
}catch(Exception e){
System.err.println(e.toString());
System.err.println(e.getStackTrace());
e.printStackTrace();}
try{
SampleSPPServer sampleSPPServer=new SampleSPPServer();
sampleSPPServer.startServer();
}catch(Exception e){
System.err.println(e.toString());
System.err.println(e.getStackTrace());
e.printStackTrace();}
}
}
this simple example throws nullpointerexception at localDevice related line 51. if i comment out line 51 & 52, another nullpointerexception is thrown at streamConnecion related line 30.
i have CSR Usb Bt device by WIDCOMM which works regularly, and i am using netbeans 6.1 with j2me wtk 2.5.2 libraries.
what i needed is, a small j2se application that will receive string via bt. can you help me, please?
---
den