Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 9
Registered: ‎07-16-2009
My Device: Not Specified

Problems with setting up Bluetooth server

I am trying to write a BT server for a BB 8310 using J2ME APIs. Here is what I have:

 

// Service UUID

 private static final UUID SERVICE_UUID = new UUID("15722ee3578d4566b0e79638cd7ee375", false);

// Server-side URL for the service

 private static final String SERVER_URL = "btspp://localhost:" + SERVICE_UUID + ";name=My Server";

 

 

// Registers our SDDB record

 private void startServer() throws BluetoothStateException, IOException

{

    StreamConnectionNotifier btService = (StreamConnectionNotifier) Connector.open(SERVER_URL, Connector.READ_WRITE);

   ServiceRecord service = LocalDevice.getLocalDevice().getRecord(btService); 

   System.out.println("Server started. Connect at " + service.getConnectionURL(ServiceRecord.AUTHENTICATE_NOENCRYPT, false));

    if (!LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.LIAC))        System.out.println("Cannot switch device to discoverable mode. Will launch the service anyway but you need to manually switch the device to discoverable mode");    StreamConnection btConnection = btService.acceptAndOpen();

   RemoteDevice remoteDevice = RemoteDevice.getRemoteDevice(btConnection);   System.

out.println("Received a connection from " + remoteDevice.getFriendlyName(false));

}

 

 

I wrote a simple client (runs on my Windows desktop and uses Bluecove API), that connects to the server and sends some data:

String connUrl = "btspp://001CCC0BA83A:5;authenticate=true;encrypt=false;master=false";

 

StreamConnection streamConnection = (StreamConnection)Connector.open(connUrl);

DataOutputStream dataout = streamConnection.openDataOutputStream();

byte[] msg = "Hello".getBytes();dataout.writeInt(msg.length);

dataout.write(msg);

dataout.flush();

Thread.sleep(10000);   // tried with and without this statement - same result

streamConnection.close();

 

 The send goes through, the server (phone) receives the connection (it asks me to confirm the connection request), but the server never goes beyond acceptAndOpen(). I am lost...

 

This is the only information the phone prints in its log during the client's execution:

BT: HCI ACCEPT_CON_REQ

BT: BTEVENT_LINK_CONNECT

BT: ROLE_CHANGE: 1 err=0

net.rim.bluetooth: DC00

net.rim.bluetooth: EC02

BT: BTEVENT_ENCRYPT_COMPLETE

AUTHORIZATION_REQ: 1

BT: PAIRING_COMPLETE

 

Do the statements I highlighted shed any light on my problem?

 

Any help would be greatly appreciated!

 

-Eugene

Highlighted
New Developer
Posts: 92
Registered: ‎01-23-2009
My Device: Z10
My Carrier: klarmobil

Re: Problems with setting up Bluetooth server

Looks like you port number (5 in 001CCC0BA83A:5) may be wrong. It is not impossilbe that there is more than one service behind a pariticular uuid. If you hardcode your access url instead of starting a search you may access the wrong service.