Listing 1

import javax.bluetooth.*;
import javax.microedition.io.*;
import com.atinav.bcc.*;


  BCC.setPortName("COM1");
  BCC.setBaudRate(57600);
  BCC.setConnectable(true);
  BCC.setDiscoverable(DiscoveryAgent.GIAC);


Listing 2

// retrieve the local Bluetooth device object
LocalDevice local = LocalDevice.getLocalDevice();
// retrieve the name of the local Bluetooth device
String name = local.getFriendlyName();


Listing 3

LocalDevice localdevice = LocalDevice.getLocalDevice();
DiscoveryAgent discoveryAgent = localdevice.getDiscoveryAgent();
discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);


Listing 4

// Service registration

// invoke Connector.open with a server connection URL argument
StreamConnectionNotifier service =
    (StreamConnectionNotifier) Connector.open("someURL");

// Obtain the service record created by the server device
ServiceRecord sr = local.getRecord(service);

// Indicate that the service is ready to accept a client connection. acceptAndOpen() blocks
//   until a client connects.
StreamConnection connection =
    (StreamConnection) service.acceptAndOpen();

// DO SOME EXCHANGE HERE

service.close();

Listing 5

String url =
    serviceRecord.getConnectionURL(
        record.NOAUTHENTICATE_NOENCRYPT, false);
// open a connection to the server
StreamConnection connection =
    (StreamConnection) Connector.open(url);
// Send/receive data
try {
    byte buf[] = new byte[200];
    String msg = "Test message";
    InputStream is = connection.openInputStream();
    OutputStream os = connection.openOutputStream();
    // send data to the server
    os.write(msg.getBytes);
    // read data from the server
    is.read(buf);
    connection.close();
} catch(IOException e) {
    e.printStackTrace();
}