Click to See Complete Forum and Search --> : Bluetooth connection fails


I am blue
April 20th, 2005, 11:40 AM
Why does the connection going down on the following code???:

int main(int argc, char* argv[])
{

WSADATA wsaData;

int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );

if ( iResult != NO_ERROR )
{
printf("Error at WSAStartup()\n");
exit(1);
}

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

if (s == INVALID_SOCKET)
{
printf(GetLastErrorMessage(GetLastError()));
exit(1);
}

SOCKADDR_BTH bthSockAddr;
bthSockAddr.addressFamily=AF_BTH;
bthSockAddr.btAddr=(BTH_ADDR)0x000e6d8e8a98;
bthSockAddr.port=BT_PORT_ANY;
bthSockAddr.serviceClassId=SerialPortServiceClass_UUID;

if(0!=connect(s,(sockaddr*)&bthSockAddr,sizeof(bthSockAddr)))
printf(GetLastErrorMessage(GetLastError()));
else
{
printf("Connected\n");
getchar();
}

if(0!=closesocket(s))
printf("failed to close socket");


WSACleanup();

return 0;

}

drewdaman
April 21st, 2005, 12:05 PM
at what stage does the connection go down? i mean.. you do close the socket so it should go down at the end of your code...

I am blue
April 25th, 2005, 11:12 AM
Well, I meant _getch() inestead of getchar(), sorry. The thing is that I want the connection opened till I press any key in the keyboard.But...
the connection goes down before I press any key. The secuence of what happens is something like this: (connection from PC to Nokia 6600)
Run programm on computer, then I accept connection on the phone. everything seems to be right (there is a small item that appears on the screen of the mobile phone when a Bluetooth connection is stablished), because that item is there. Then it dissapears, 2 or 3 seconds later appears again and then definitely dissapears.I also cpntrol the status of the connection looking in the bluetoothmanager of microsoft, and there I see the same that I see on my phone(connected-not connected-connected-not connected and not connect again).
I have started thinking that probably something goes wrong in the mobile (doesnīt accept the connection or something like that, but I canīt exactly figure out what's going on).
Any help will be well recibed.

LyNdA^
June 12th, 2005, 08:23 AM
Where can i get the Ws2bth.h header file?

MikeAThon
June 13th, 2005, 04:30 PM
I think it is part of the current platform SDK. See "About Bluetooth" at http://msdn.microsoft.com/library/en-us/bluetooth/bluetooth/about_bluetooth.asp

Remember to "#include Ws2bth.h" after the #include to Winsock2.h to use Bluetooth sockets.

Mike

Tatu
February 22nd, 2011, 03:44 AM
Hi,

I would like to ask during the connect(s,(sockaddr*)&bthSockAddr,sizeof(bthSockAddr),
the handphone will ask for key in the pass code, and the computer shud oso send a same passcode, so how I can set this passcode???

Best Regard