I have used this library to in my application(https://github.com/kenjdavidson/react-native-bluetooth-classic-apps/tree/main/BluetoothClassicExample) to make a connection to bluetooth devices.
I am getting this issue - Connection failed: java.io.IOException read failed, socket might closed or timeout, read ret: -1 while connecting to a device.
Here is the code code i used for connect() function. (Referred this code from https://kenjdavidson.com/react-native-bluetooth-classic/react-native/rn-bluetooth-device/)
async connect() {
try {
let connection = await this.props.device.isConnected();
console.log("connection is......", connection);
if (!connection) {
console.log(this.state.connectionOptions);
connection = await this.props.device.connect({
CONNECTOR_TYPE: "rfcomm",
DELIMITER: "\n",
DEVICE_CHARSET: Platform.OS === "ios" ? 1536 : "utf-8",
});
} else {
console.log("Connected to ", this.props.device.name)
}
this.setState({ connection });
this.initializeRead();
} catch (error) {
console.log(error.message)
}
}
Can someone suggest me the solution