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 |
| WSAEISCONN 10056
| The connect function called for already connected socket. |
| WSAEACCES 10013
| Connecting application requested authentication, but authentication failed. |
| WSAENOBUFS 10055
| Unrecoverable out-of-memory error. |
| WSAEADDRINUSE 10048
| The port/channel number requested is in use. |
| WSAETIMEDOUT 10060
| The I/O timed out at the Bluetooth radio level (PAGE_TIMEOUT). |
| WSAEDISCON 10101
| The RFCOMM channel disconnected by remote peer. |
| WSAECONNRESET 10054
| The RFCOMM multiplexor (session) disconnected by remote peer. |
| WSAECONNABORTED 10053
| Socket shut down by application. |
| WSAENETUNREACH 10051
| Error other than time-out at L2CAP or Bluetooth radio level. |
| WSAEHOSTDOWN 10064
| The RFCOMM received DM response. |
| WSAENETDOWN 10050
| Unexpected network error. |
| WSAESHUTDOWN 10058
| The L2CAP channel disconnected by remote peer. |
| WSAEADDRNOTAVAIL 10049
| Bluetooth port/channel or device address not valid. |
| WSAEINVAL 10022
| Plug and Play, driver-stack event, or other error caused failure. |
See Also
- Windows Sockets
- connect
- SOCKADDR_BTH
Send comments about this topic to Microsoft
Build date: 6/11/2009