Error 10051 Windows sockets connect()

I'm having trouble connecting to a bluetooth device in Windows Sockets 2. When I use the connect() function, it returns the error 10051, which according to MSDN means that "A socket operation was attempted to an unreachable network". What can I do to troubleshoot this? I'm pretty sure at this point it isn't a problem with my code, but here it is anyway:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <Ws2bth.h>
#include <string>
#include <iostream>

#pragma comment(lib, "Ws2_32.lib")


int main()
{
	WSADATA init;
	WSAStartup(MAKEWORD(2, 2), &init);

	SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);

	SOCKADDR_BTH name;
	name.addressFamily = AF_BTH;
	name.btAddr = 0x001B7A4060FA;
	name.port = 10;
	name.serviceClassId = RFCOMM_PROTOCOL_UUID;
	if (connect(s, (sockaddr *)&name, sizeof(name)) != 0)
	{
		std::cout << "could not connect. reason: " << WSAGetLastError() << "\n";
	}
	while (true);
}


Any help is greatly appreciated!
Last edited on
Topic archived. No new replies allowed.