1

モバイル アプリケーション (J2ME および JSR82 を使用) とデスクトップ アプリケーション (InTheHand ライブラリを使用する C#) の間で通信を行おうとしています。

UUID: 00000003-0000-1000-8000-00805f9b34fb の RFComm プロトコルを使用しています。

両方のデバイスで uuid を手動で指定しました。デスクトップアプリケーションがデータを送信している間、着信接続を待機するモバイルアプリケーションがあります。

しかし、私のモバイル アプリケーションは着信接続をリッスンしません。「着信接続を待機しています...」というメッセージでハングするだけです。

モバイル アプリケーションの J2ME コード:

public void startApp() {
    if (midletPaused) {
        resumeMIDlet();
    } else {
        initialize();
        startMIDlet();

        form.append("UID: "+ uuid.toString() +"\n");
        //set the device discoverable
        try {
            LocalDevice localDevice = LocalDevice.getLocalDevice();
            localDevice.setDiscoverable(DiscoveryAgent.GIAC);
            form.append("Device Address: "+localDevice.getBluetoothAddress()+"\n");
            form.append("Name: "+ localDevice.getFriendlyName()+"\n");
        }
        catch (BluetoothStateException exception) {
            form.append(exception.toString()+"\n");
        }

        //setup a server socket
        StreamConnectionNotifier streamConnectionNotifier = null;
        try {
            String url = "btspp://localhost:000300001000800000805f9b34fb;name=rfcommtest;authorize=true";
            //form.append(url);
            streamConnectionNotifier = (StreamConnectionNotifier)Connector.open(url);
            if (streamConnectionNotifier == null) {
                form.append("Error: streamConnectionNotifier is null\n");
                return;
            }
        }
        catch (Exception exception) {
            form.append(exception.toString()+"\n");
        }

        //wait for an incoming connection
        StreamConnection streamConnection = null;
        try {
            form.append("Waiting for incoming connection...\n");
            streamConnection = streamConnectionNotifier.acceptAndOpen();
            if (streamConnection == null) {
                form.append("Error: streamConnection is null\n");
            } else {
                form.append("Connection received.\n");
            }
        }
        catch (Exception exception) {
            form.append(exception.toString()+"\n");
        }

        //write hello and then exit
        try {
            OutputStream out = streamConnection.openOutputStream();
            form.append("Stream \n");
            String s = "hello";
            out.write(s.getBytes());
            out.flush();
            streamConnection.close();
            form.append("Text Written to stream\n");
        }
        catch (Exception exception) {
            form.append(exception.toString()+"\n");
        }


    }
    midletPaused = false;
}

デスクトップ アプリの C# コード:

        cli = new BluetoothClient();

        BluetoothEndPoint ep1 = new BluetoothEndPoint(info[listBox1.SelectedIndex].DeviceAddress, BluetoothService.RFCommProtocol);

        cli.Connect(ep1);

        Stream stream = cli.GetStream();

        StreamWriter sw = new StreamWriter(stream);

        sw.WriteLine("Tesing");
        sw.WriteLine("testing");
        sw.Flush();
        sw.Close();

        stream.Close();

これについて私を助けてください。

4

0 に答える 0