Bluetooth and connect
Bluetooth uses the connect function to connect to a target Bluetooth device, using a previously created Bluetooth socket. The name parameter of the connect function, which is a SOCKADDR_BTH structure, must specify a target Bluetooth device. Two mechanisms are used to identify the target device:
- The SOCKADDR_BTH structure can directly specify the port number to which a connect is requested. This mechanism requires the application to perform its own SDP queries prior to attempting a connect operation.
- The SOCKADDR_BTH structure can specify the unique service class ID of the service to which it wants to connect. If the peer device has more than one port that corresponds to the service class ID, the connect function call connects to the first valid service. This mechanism can be used without prior SDP queries.
- The btAddr member must be a valid remote radio address.
- For the serviceClassId member, if the port member is zero, the system attempts to use serviceClassId to resolve the remote port corresponding to the service. The service class is a normalized 128-bit GUID, defined by the Bluetooth specification. Common GUIDs are defined by the Bluetooth Assigned Numbers document. Alternatively, a unique GUID may be used for a domain-specific application.
- The port member must be a valid remote port, or zero if the serviceClassId member is specified.
The following table lists the result codes for Bluetooth and the connect function.
||The connect function called for already connected socket.|
||Connecting application requested authentication, but authentication failed.|
||Unrecoverable out-of-memory error.|
||The port/channel number requested is in use.|
||The I/O timed out at the Bluetooth radio level (PAGE_TIMEOUT).|
||The RFCOMM channel disconnected by remote peer.|
||The RFCOMM multiplexor (session) disconnected by remote peer.|
||Socket shut down by application.|
||Error other than time-out at L2CAP or Bluetooth radio level.|
||The RFCOMM received DM response.|
||Unexpected network error.|
||The L2CAP channel disconnected by remote peer.|
||Bluetooth port/channel or device address not valid.|
||Plug and Play, driver-stack event, or other error caused failure.|