Bluetooth and bind

Bluetooth uses the bind function to bind to a socket. To bind a Bluetooth socket, call the bind function using the SOCKADDR_BTH structure. Use the SOCKADDR_BTH structure with the following settings:

name.addressFamily = AF_BTH;
name.btAddr = 0;
name.serviceClassId = GUID_NULL;
name.port = number of service channel, 0 or BT_PORT_ANY;

On client applications, the port member must be zero to enable an appropriate local endpoint to be assigned. On server applications, the port member must be a valid port number or BT_PORT_ANY; ports automatically assigned using BT_PORT_ANY may be queried subsequently with a call to the getsockname function. The valid range for requesting a specific RFCOMM port is 1 through 30. Server channels are global resource, and only 30 server channels are available for RFCOMM on any Bluetooth device, which must be shared by all Windows Sockets that belong to the Bluetooth address family. If no server channel is available, or if the specified server channel is already reserved, the bind call fails.

Upon successful return from bind, the server channel is reserved until the socket is closed. Use the getsockname function to retrieve the channel number for SDP registration.

Applications should use auto-allocation for the server channel.

The bind function does not automatically advertise the server application using the Bluetooth SDP; applications must call the WSASetService function to be found by remote Bluetooth applications.

Windows Sockets

bind