2

eclipse / WTK 2.5.2 で J2ME プログラムを開発していますが、Bluetooth を使用して 2 つのエミュレーターを接続する際に問題があります。1 つのサーバーと 1 つの .client が 2 つの異なるエミュレーターで実行されています。

問題は、クライアント プログラムが Bluetooth デバイスを検出できないことです。サーバーとクライアントのコードは次のとおりです。

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)
    {}
}

Connector.open を呼び出した後、コンソールに次の警告が表示されます。これは関連していると思われます。

警告: 未登録のデバイス: 未指定

デバイスを検索するクライアント コード:

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)
    {}
}

システムは deviceDiscovered を呼び出すことはありませんが、inquiryCompleted() を INQUIRY_COMPLETED パラメータで呼び出すため、クライアント プログラムは正常に動作すると思います。

エミュレータの設定で Bluetooth が有効になっています。

4

1 に答える 1

3

NetBeans IDE 6.8 とほぼ同じコードを WTK 2.5.2_01 エミュレータでテストしたところ、うまく動作しました。(つまり、デバイスを発見したということです)

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());
}

このコードは、以下のログを出力します。

サーバーから:

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

クライアントから:

Device Bluetooth Address: 0123456789AF
device discovered:RemoteDevice[address=0000000DECAF, name=null, encrypted=false, authenticated=false]
于 2010-03-16T04:09:57.650 に答える