开发者

Bluetooth Android to Windows 7

开发者 https://www.devze.com 2023-03-12 21:14 出处:网络
I am trying to make an application that transfers Strings of data from my Android p开发者_如何学编程hone to my Laptop running Windows 7 (and Vice-Versa) over Bluetooth.

I am trying to make an application that transfers Strings of data from my Android p开发者_如何学编程hone to my Laptop running Windows 7 (and Vice-Versa) over Bluetooth.

I figured that I would open up a Server-Socket on the Windows Machine and program the Android app to start a Client-Socket. But being aware that Android SDP(Service Discovery Protocol) and connects By a UUID, created a point where in I am confused.

Confused on how I should start up a server socket on the Server Side Using the Windows API. MY Question is whether android will detect the server socket if I merely start a Bluetooth socket with

SOCKET sock_s, sock_c;
SOCKADDR_BTH add1,add2;
sock_s =socket( AF_BTH,SOCK_STREAM,BTHPROTO_RFCOMM );
        if ( sock_s == INVALID_SOCKET )
            return -2;

        //Clearing the SOCKADDR_BTH variable
        memset(&add1,0,sizeof(add1));

        add1.addressFamily=AF_BTH;
        add1.serviceClassId=my_Guid;

Or is there another way to create a server socket that follows the SDP protocol on the MICROSOFT stack?


Do you have to use native code on the Windows box? If not use my library (32feet.NET) its make such things easy e.g. Bluetooth Server-side:

Class MyConsts
  Shared ReadOnly MyServiceUuid As Guid _
    = New Guid("{00112233-4455-6677-8899-aabbccddeeff}")
End Class

  ...
  Dim lsnr As New BluetoothListener(MyConsts.MyServiceUuid)
  lsnr.Start()
  ' Now accept new connections, perhaps using the thread pool to handle each
  Dim conn As New BluetoothClient = lsnr.AcceptBluetoothClient()
  Dim peerStream As Stream = conn.GetStream()
  ...

You could even 32feet.NET use it from C++ with C+++/CLR.

Or IIRC there is a simple way to get Windows WSASetService to add a basic SDP record for your server socket (if you don't have a custom record to add). Or get the RFCOMM port number from the Windows socket (getsockname) and tell the Android app to connect directly to that port number -- assuming it can do that...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号