Dev.eloper
Dev.eloper

Reputation: 1

How to send string messages via bluetooth in flutter?

I want to send messages between two phones via bluetooth I am using flutter_blue_plus package and i am not understanding on how to send string messages and receive them, what characteristic to use or descriptor or service.

If its possible i want to listen to the messages received by the other device connected via bluetooth.

I also wanted to know if nearby connections api can be use to connect phones to bluetooth low energy devices? i want to try both since bluetooth low energy is the priority, i am skeptical about nearby connection api.

D/uuid    (17373): 00001101-0000-1000-8000-00805f9b34fb
I/flutter (17373): STATE_CONNECTED
W/BluetoothAdapter(17373): getBluetoothService() called with no 
BluetoothManagerCallback
D/STATUS_CONNECT(17373): java.io.IOException: read failed, socket 
might closed or timeout, read ret: -1
I/flutter (17373): FC:02:96:56:FE:55
I/flutter (17373): STATE_DISCONNECTED

Why am i getting disconnected as soon as i connect? is that because of my phone? I am trying to connect to my other phone also is i think thats the reason its throwing read failed exception

Upvotes: 0

Views: 1322

Answers (1)

Churanta Mondal
Churanta Mondal

Reputation: 1

If you are using flutter Bluetooth serial, then I recommend you to use github repository recommended by flutter.dev https://github.com/edufolly/flutter_bluetooth_serial

and if you want to send message then go to examples/lib/chatpage.dart there you can send any message using

_sendMessage("Hello World");

or you can just send messages using

_sendMessage("Hello World");

Upvotes: 0

Related Questions