I'm trying to get 2 laptops with bluetooth to connect. This is the code I'm using for making a server:
WSADATA wsd;
WSAStartup (MAKEWORD(1,0), &wsd);
SOCKET server_socket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
SOCKADDR_BTH sa;
memset(&sa, 0, sizeof(sa));
sa.addressFamily = AF_BTH;
sa.port = 0 & 0xFF;
if(0 != bind(server_socket, (SOCKADDR *)&sa, sizeof(sa)))
{
std::cout << "BIND ERROR: " << WSAGetLastError () << std::endl;
closesocket(server_socket);
return false;
}
if(0 != listen (server_socket, 5))
{
std::cout << "LISTEN ERROR: " << WSAGetLastError () << std::endl;
closesocket(server_socket);
return false;
}
SOCKADDR_BTH sa2;
int size = sizeof(sa2);
SOCKET s2 = accept(server_socket, (SOCKADDR*)&sa2, &size);
if(s2 == INVALID_SOCKET)
{
std::cout << "ACCEPT ERROR: " << WSAGetLastError () << std::endl;
return false;
}
else
{
std::cout << "Connected? " << WSAGetLastError () << std::endl;
}
and the following as a client:
WSADATA wsd;
WSAStartup (MAKEWORD(1,0), &wsd);
SOCKET client_socket = socket (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
SOCKADDR_BTH sa;
memset (&sa, 0, sizeof(sa));
sa.addressFamily = AF_BTH;
sa.btAddr = (BTH_ADDR)d.getDeviceAddress();
sa.port = 0;
sa.serviceClassId = *d.getLpServiceClassId();
if(client_socket == INVALID_SOCKET)
{
std::cout << "SOCKET ERROR: " << WSAGetLastError () << std::endl;
return false;
}
if (0 != connect (client_socket, (SOCKADDR *)&sa, sizeof(sa)))
{
std::cout << "CONNECT ERROR: " << WSAGetLastError () << std::endl;
return false;
}
else
{
//std::cout << "CONNECT ERROR: " << WSAGetLastError () << std::endl;
//Perform error handling.s
send(client_socket, "ABC",3,0);
closesocket (client_socket);
return true;
}
Where "b" is the bluetooth device I give as argument the bluetoothdevice class has the following fields:
LPSOCKADDR local_address;
LPSOCKADDR device_address;
LPGUID lp_service_class_id;
This SHOULD work. But when I try to connect to the server, the server gets nothing and the client gives me error 10060.
This error means:
WSAETIMEDOUT 10060
The I/O timed out at the Bluetooth radio level (PAGE_TIMEOUT).
Is there anyone out here who has worked with the bluetooth stack on windows and knows where this error comes from?