Bluetooth socket returns WSAEPROTONOSUPPORT
For a project I am working on I would like to have an Embedded System to act as a Bluetooth server. I got the driver for my USb-Bluetooth working and in the Control Panel I now have a "Bluetooth Device Properties"-option which works and detects other devices via the Bluetooth USB dongle.
However when I try to use the dongle in code, I get an error.
The Includes are:
winsock2.h, ws2bth.h, bt_sdp.h, bthapi.h, bt_api.h, winioctl.h, windows.h
This is the code:
int Main(int argc, char **argv)
{
WSADATA wsd;
if (WSAStartup(MAKEWORD(2, 2), &wsd)){
wprintf(L"Initialization of socket subsystem failed! Error = %dn", WSAGetLastError());
return 0;
}
SOCKET server = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if(server == INVALID_SOCKET){
printf("socket failed, error %dn", WSAGetLastError());
return 0;
}
return 0;
}
This compiles, but when running it fails at the socket creation. GetLastError returns 10043, which means WSAEPROTONOSUPPORT. A quick search gives me this list with error codes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx
I have no idea what I'm doing wrong. The code runs on a normal laptop with bluetooth, so I suspect it has something to do with the driver or so. Any help is appreciated!
Kind Regards
链接地址: http://www.djcxy.com/p/58320.html