语言

Menu
Sites
Language
create bluetooth service failed in web app

I register a service in web app, when someone connects to the service, the service seems to be hanged if I try to assign callback to the onmessage of socket in onconnect function of BluetoothServiceSuccessCallback. The code is as following:

var uuid = "5BCE9431-6C75-32AB-AFE0-2EC108A30860";

adapter.registerRFCOMMServiceByUUID(uuid, "service", function(handler) {

    handler.onconnect = function(socket) {

       alert("1");

        socket.onmessage = function() {

            ...

        };

        alert("2");

    }

});

The first alert can be executed but the second can not. That is the "2" is never alerted. But if I commented the "socket.onmessage = function() {...}", the second alert executes. That's really strange. Can someone help me?

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

5 回复
Raghavendra Reddy Shiva
For your service to hang, there might be some issue in your "socket.onmessage" handling function. And the reason for alert("2") not invoked is due to the callback function scoping. The BluetoothServiceHandler's onconnect event has the handlers (onmessage/onclose) on success. So when a message is received from a client the "socket.onmessage" is executed and the alert(2) is placed after this handler, which will not be invoked. Try placing the required code under the "socket.onmessage" handler scope. Also refer the Tizen Sample application "Bluetooth chat" for reference.
Lei Wei
hi, I tried the sample application "Bluetooth chat". The same problem exists. The version of my device is tizen 2.1. Does that matter?
Raghavendra Reddy Shiva
The sample application works fine. How did you test the sample application ? You should be installing the same apps on 2 different Tizen devices (2.1 or 2.2) to test. There are only few methods added in 2.2 release, so shouldn't be a problem with 2.1 devices. Anyways suggest to upgrade to 2.2 image sooner.
Lei Wei
When I run the sample on my device, I tried to join server on one phone but it stays at the 'Choose your server' page while the 'send' button on the server side remains grey. The connection seems to be failed.
Lei Wei
I found that the client and server side all block at the assignment to socket.onmessage.