Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function associates a local address with a socket.
Note: |
---|
This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth. |
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 from the SOCKADDR_BTHstructure.
- namelen
-
[in] Length of the value in the name parameter.
Return Value
If no error occurs, this function returns zero. If an error occurs, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.
Remarks
To bind a Bluetooth socket, namemust be SOCKADDR_BTH, with the following members:
name.addressFamily= AF_BTH;
name.btAddr= 0;
name.serviceClassId= GUID_NULL;
name.port= number of service channel or 0;
If the port is 0, the port will be 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 fail.
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 future Bluetooth profile specification. Currently, there are no profiles that fix channel numbers.
The following example code shows how to use auto-allocation for a server channel.
Copy Code | |
---|---|
SOCKADDR_BTH sab; memset (&sab, 0, sizeof(sab)); sab.addressFamily = AF_BTH; sab.port = 0; // auto-allocate server channel |
For more information about the bindfunction, see bind (Windows Sockets)in the Winsock reference.
Requirements
Header | winsock2.h |
Library | Ws2.lib |
Windows Embedded CE | Windows CE .NET 4.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |
See Also
Reference
Bluetooth Application Development Functionsgetsockname (Bluetooth)