Advertisement

03.07.2005 at 11:21AM PST, ID: 21341020
[x]
Attachment Details

Bluetooth Winsock (problems with my code)

Asked by lkutor in Bluetooth

Tags: bluetooth, winsock, sockaddr_bth

Hi!
I have a code, which can discover devices, and return their name and addresses. That's fine. But I can't estabilish a connection... Here is the code:


(I had intialize Winsock, and opened a Bluetooth socket. The device discovery works, and the LUP_RETURN_ADDR flag is set at the WSALookupServiceNext)
---------------------------------------------------------------------------------------------------------------------------------------------------------
...
unsigned short addressAsString[1000];
DWORD addressSize = sizeof(addressAsString);
addressSize = sizeof (addressAsString);
if (0==WSAAddressToString(pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr, pwsaResults->lpcsaBuffer->RemoteAddr.iSockaddrLength, &protocolInfo, addressAsString, &addressSize))
               {
      MessageBox(hDlg, _T("Convert complete"), _T("WSAAddressToString"), MB_OK);
      if (pwsaResults->lpcsaBuffer)
                      {
                      SendMessage(GetDlgItem(hDlg, IDC_DEVLIST),
                      LB_ADDSTRING,
            0,
            (LPARAM)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr);
            }                  
      }      
      else
      {
            MessageBox(hDlg, _T("Convert incomplete"), _T("WSAAddressToString"), MB_OK);
      }

SOCKADDR_BTH address;
memset (&address, 0, sizeof(address));
address.addressFamily = AF_BTH;
address.btAddr = 0; //pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr;
address.port = BT_PORT_ANY;
            
sockaddr *pAddr = (sockaddr *)&address;
if (0!= bind(s, pAddr, sizeof(SOCKADDR_BTH)))
      {
      MessageBox(hDlg, _T("bind sikertelen!"), _T("BIND"), MB_OK);
      }

      if (0 != connect(s, pAddr, sizeof(SOCKADDR_BTH)))
                       {
            MessageBox(hDlg, _T("nem sikerült kapcsolódni") , _T("connection failed"), MB_OK);
            }
      else
            {
            MessageBox(hDlg, _T("Kapcsolódva!"), _T("AFTER BIND/CONNECT"), MB_OK);
            }
...
---------------------------------------------------------------------------------------------------------------------------------------------------------
In all three cases (WSAAddressToString, bind and connect) I get to the ELSE, so all of them unsuccsessful. In the case of the WSAAddressToString I don't really know what can be the problem, but when thinking about bind and connect I'm pretty sure that somethings wrong with the SOCKADDR_BTH structure, becouse I miss the "address.serviceClassId = ". That's becouse that I can't give them a valid value? I tried GUID_NULL, but don't worked.
Maybe I'm on a totally wrong way... What is your suggestion, about this? How can I connect to a device, which I have it's name and address using Winsock functios?

(I don't know if it's a problem or not, but I use only LUP_CONTAINERS at WSALookupServiceBegin, and LUP_RETURN_NAME | LUP_RETURN_ADDR at WSALookupServiceNext)

Thanks in advance,
AndreWStart Free Trial
[+][-]03.18.2005 at 10:55AM PST, ID: 13577357

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.27.2005 at 05:08AM PDT, ID: 14307664

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.30.2005 at 04:59PM PDT, ID: 14343705

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2005 at 12:58AM PDT, ID: 14345288

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Bluetooth
Tags: bluetooth, winsock, sockaddr_bth
Sign Up Now!
Solution Provided By: modulo
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32