Winapi connect to bluethooth failed,error OS code 10060

Hey guys, I'm programing a rust project to connecting bluetooth device and communicating with it on Windows, and use a lib named "IO-BLUETOOTH-MASTER", the only dependency is WinAPI.\
Now discovey device is working well. But connecting to device is a big problem. As usual, connecting t o Iphone and Android are OK, but when I connected to an embedded ble chip, it will working wrong.\
The main code is :
fn main() -> io::Result<()> {
    let devices = bt::discover_devices()?;
    println!("Devices:");
    for (idx, device) in devices.iter().enumerate() {
        println!("{}: {}", idx, *device);
    }

    if devices.len() == 0 {
        return Err(io::Error::new(
            io::ErrorKind::NotFound,
            "No Bluetooth devices found.",
        ));
    }

    let device_idx = request_device_idx(devices.len())?;

    let socket = BtStream::connect(iter::once(&devices[device_idx]), bt::BtProtocol::RFCOMM)?;
}
You can see this demo is using Sock to listening to message and bluetooth stream, and address is bond to 127.0.0.1, I can sure that I didn't make this mistake, but the error had occured.

Error: Os { code: 10060, kind: TimedOut, message: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." }

Sometime the error is : Code 10049, but when I change a chip, the error is always 10060
The connect method code is :

pub struct BtStream {
    inner: Socket,
    protocol: BtProtocol,
}

impl BtStream {
    pub fn connect(addr: &BtAddr, protocol: BtProtocol) -> io::Result<Self> {
        let (addr, len) = addr.into();

        let socket = Socket::new(protocol)?;
        cvt_r(|| unsafe { c::connect(*socket.as_inner(), &addr as *const _ as *const _, len) })?;
        Ok(Self {
            inner: socket,
            protocol,
        })
    }

Also I can sure that the chip's fuction is OK, I can use the ble tool to communicate with it on Android, and using the BlueTooth privide by Windows is also can't connect to the device, but they can paired.

I'm just a beginner for rust, please be tolerant if I made some ridiculous mistake

This is the wrong forum. You want https://users.rust-lang.org

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.