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.
When using the SOCKADDR_BTH structure with the connect function, the following requirements apply:
- 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.
Error/error# | Description |
---|---|
WSAEISCONN10056 |
The connect function called for already connected socket. |
WSAEACCES10013 |
Connecting application requested authentication, but authentication failed. |
WSAENOBUFS10055 |
Unrecoverable out-of-memory error. |
WSAEADDRINUSE10048 |
The port/channel number requested is in use. |
WSAETIMEDOUT10060 |
The I/O timed out at the Bluetooth radio level (PAGE_TIMEOUT). |
WSAEDISCON10101 |
The RFCOMM channel disconnected by remote peer. |
WSAECONNRESET10054 |
The RFCOMM multiplexor (session) disconnected by remote peer. |
WSAECONNABORTED10053 |
Socket shut down by application. |
WSAENETUNREACH10051 |
Error other than time-out at L2CAP or Bluetooth radio level. |
WSAEHOSTDOWN10064 |
The RFCOMM received DM response. |
WSAENETDOWN10050 |
Unexpected network error. |
WSAESHUTDOWN10058 |
The L2CAP channel disconnected by remote peer. |
WSAEADDRNOTAVAIL10049 |
Bluetooth port/channel or device address not valid. |
WSAEINVAL10022 |
Plug and Play, driver-stack event, or other error caused failure. |