bind (Bluetooth) (Compact 2013)
3/26/2014
This function associates a local address with a socket.
Syntax
int bind(
SOCKET s,
const struct sockaddr FAR* name,
int namelen
);
Parameters
- s
[in] Descriptor identifying an unbound socket.
- name
[in] Address to assign to the socket. For details see Remarks.
- namelen
[in] Length of the value in the name parameter.
Return Value
Returns zero on success; otherwise SOCKET_ERROR. The specific error code can be retrieved by calling WSAGetLastError.
Remarks
Note
This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth.
To bind a Bluetooth socket, name must be a SOCKADDR_BTH structure with the following member values:
Member |
Value |
---|---|
addressFamily |
AF_BTH |
btAddr |
0 |
serviceClassId |
GUID_NULL |
port |
Number of service channel or 0. |
If the port is 0, the port is allocated automatically. Remember that server channels are a global resource and there are a total of 31 server channels available for RFCOMM on any Bluetooth device for all applications to share (both Winsock and virtual COM ports).
If there is no available server channel, or the specified server channel is already reserved by another application, the call will not succeed.
If the call succeeds, the server channel is reserved until the socket is closed. Use getsockname (Bluetooth) to retrieve the channel number (for SDP registration).
It is recommended that an application always use auto-allocation for a server channel, unless a fixed server channel is specified by a Bluetooth profile specification. Currently, there are no profiles that require fixed channel numbers.
For more information about the bind function, see bind (Windows Sockets) in the Winsock reference.
Example
The following example code shows how to use auto-allocation for a server channel.
SOCKADDR_BTH sab;
memset (&sab, 0, sizeof(sab));
sab.addressFamily = AF_BTH;
sab.port = 0; // auto-allocate server channel
Requirements
Header |
winsock2.h |
Library |
Ws2.lib |
See Also
Reference
Bluetooth API Miscellaneous Functions
getsockname (Bluetooth)