tanelih / phonegap-bluetooth-plugin

Bluetooth plugin for PhoneGap version 2.6.0+
MIT License
57 stars 50 forks source link

Troubles to send data from an android phone to another #27

Open Brileantag opened 10 years ago

Brileantag commented 10 years ago

Hi! I am facing with a problem when i try to send strings from an Android phone to another one (Sender: android 4.2, receiver: android 4.1). The functions discover, connect, pair, enable, startConnectionManager work fine. The write one also seems to work good, because the Success callback is called after have written. After that, the device on which the writter is connected is never notified by any data received. Here are more details:

I have seen on Stackoverflow that the problem was caused by the fact that i start the connection manager on both devices. Does this still in instance? i have tried to implement the solution given in that post unsuccessfully. Please, how could i turn round this problem?

tanelih commented 10 years ago

Hi,

The plugin does not actually have any way to accept incoming connections, so even though your receiving device is connected to the device that is writing, they are not communicating through a "shared" socket.

As you can see on StackOverflow, you would need to implement an AcceptThread that would poll for incoming connections in order to receive a socket that both of the devices would know of and could communicate through.

Brileantag commented 10 years ago

Hi, i have tried to writte a java Thread to listen to incoming connections. i faced with a new problem, that is how to get the reference to the BluetoothSocket object on which the incoming connection has been made. I have seen in the plugin code that the reference of the _socket is obtained when attempting to connect. Do you know if there is a way to get this reference for the device receiving an incoming connection attempt?

Brileantag commented 9 years ago

Hi, Thank you @tanelih , i finally found how to modify the plugin after have read the android bluetooth chat source code. I have added the AcceptThread, and all is ok.

arielgpe commented 9 years ago

hey @Brileantag do you have some code to share? im having the same problem but i dont know where to start. Thanks in advance.

Brileantag commented 9 years ago

Hey @arielgpe , sorry for the late reply. I was not able to use internet for a long period. If still needed, I have a code i could share with you, a small change of the plugin source code. Do you want to have it by mail or should i paste it here?

arielgpe commented 9 years ago

@Brileantag how it is more comfortable to you? im okay with mails or repos that i can fork.

coderextreme commented 9 years ago

@Brileantag could you paste the code here or email me? Thanks

coderextreme commented 9 years ago

Would this code work to connect android 4.4.2 to windows 8.1 pc or yosemite mac os x? I haven't looked at what I have to do on desktop yet.

tanelih commented 9 years ago

@coderextreme Hi, the plugin should probably be able to connect to various devices with bluetooth capabilities, such as a desktop pc. You would have to handle the incoming connection on the desktop then.

hnthakkar commented 9 years ago

Hi @tanelih, even I am facing the same problem The devices are paired The devices are connected The connection manager is started on the two devices. The write function ends by calling the success callback but not able to send data, as @Brileantag mentioned I did try implementing the AcceptThread, but was unsuccessful, and need little more Idea on this. Can anyone please guide me on this. Thanks.

tanelih commented 9 years ago

@hnthakkar, This plugin works as a client of sorts, so it needs a server to connect to. The problem with the situation you are describing is that this plugin does not implement a server.

Take a look at this for some guidance on how to implement an AcceptThread, or a server in a sense.