开发者

WTK emulator bluetooth connection

I'm developing a J2ME program with eclipse / WTK 2.5.2 and having problem with connecting two emulators using bluetooth. There is one server and one .client running on two different emulators.

The problem is client program cannot discover any bluetooth device. Here is the server and client codes:

public Server()
{
    try
    {
        LocalDevice local = LocalDevice.getLocalDevice();
        local.setDiscoverable(DiscoveryAgent.GIAC);

        server = (StreamConnectionNotifier)   
            Connector.open("btspp://localhost:" 
                + UUID_STRING + ";name=" + SERVICE_NAME);

        Util.Log("EchoServer() Server connector open!");
    }
    catch (Exception e)
    {}
}

after calling Connector.open, I get following warning in console, which i believe is related:

Warning: Unregistered device: unspecified

and client code that searches for devices:

public SearchForDevices(String uuid, String nm)
{
    UUIDStr = uuid;
    srchServiceName = nm;
    try
    {
        LocalDevice local = LocalDevice.getLocalDevice();
        agent = local.getDiscoveryAgent();

        deviceList = new Vector();

        agent.startInquiry(DiscoveryAgent.GIAC, this); // non-blocking
    }
    catch (Exception e)
    {}
}

system never calls deviceDiscovered, but calls inquiryCompleted() with INQUIRY_COMPLETED p开发者_运维问答arameter, so I suppose client program runs fine.

Bluetooth is enabled at emulator settings..


I tested almost same code from NetBeans IDE 6.8 with WTK 2.5.2_01 emulator and it works well. (I mean it discovered device)

public void startBTServer() {
    try
    {
        LocalDevice local = LocalDevice.getLocalDevice();
        local.setDiscoverable(DiscoveryAgent.GIAC);

        StreamConnectionNotifier server = (StreamConnectionNotifier)
            Connector.open("btspp://localhost:F0E0D0C0B0A000908070605040302010"
                + ";name=" + ";test");
    }
    catch (Exception e)
    {}
}

public void startBTClient() {
    String UUIDStr = "F0E0D0C0B0A000908070605040302010";
    try
    {
        LocalDevice local = LocalDevice.getLocalDevice();
        DiscoveryAgent agent = local.getDiscoveryAgent();

        agent.startInquiry(DiscoveryAgent.GIAC, (DiscoveryListener) this);
    }
    catch (Exception e)
    {}

}

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    System.out.println("device discovered:" + btDevice.toString());
}

This code print out the below log:

From server:

Running in the identified_third_party security domain
Device Bluetooth Address: 0000000DECAF

From client:

Device Bluetooth Address: 0123456789AF
device discovered:RemoteDevice[address=0000000DECAF, name=null, encrypted=false, authenticated=false]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜