Bluetooth bind() fails with WSANETDOWN

Discussion in 'Wireless Networking' started by Brown Dwarf, Apr 10, 2006.

  1. Brown Dwarf

    Brown Dwarf Guest

    Hello there,
    This is the first time I'm probramming for bluetooth.
    I installed a USB bluetooth device and the software comes with it works
    great, detecting other devices and communicates.

    Now I'm developing an bluetooth application to run in server mode (using
    WSASetService).
    But it fails at bind() with WSANETDOWN. Any idea how to troubleshoot this ??

    Platform: WindowsXp-SP2, MSVC6

    SOCKET s = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
    DWORD lastError = ::WSAGetLastError();
    if (s == INVALID_SOCKET)
    {
    printf("Failed to get bluetooth socket! %s\n",
    GetLastErrorMessage(lastError));
    exit(1);
    }

    SOCKADDR_BTH sbth;
    memset(&sbth, 0, sizeof(sbth));
    sbth.addressFamily = AF_BTH;
    sbth.btAddr = 0;
    sbth.port = BT_PORT_ANY;

    if (bind(s, (const sockaddr*)&sbth, sizeof(SOCKADDR_BTH)) == SOCKET_ERROR)
    // <<------ here is the problem
    {
    lastError = ::WSAGetLastError(); // always WSANETDOWN
    printf("Failed to bind bluetooth socket! %s\n",
    GetLastErrorMessage(lastError));
    exit(1);
    }
     
    Brown Dwarf, Apr 10, 2006
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.