Устройство не принимает входящее соединение в J2Me Bluetooth? - PullRequest
1 голос
/ 22 марта 2012

Я пытаюсь установить связь между мобильным приложением (используя J2ME и JSR82) и настольным приложением (в C # с использованием библиотеки InTheHand).

Я использую протокол RFComm с UUID: 00000003-0000-1000-8000-00805f9b34fb.

Я вручную указал 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();

Пожалуйста, помогите мне в этом.

...