Share via


accept (Bluetooth) (Windows Embedded CE 6.0)

1/6/2010

This function permits an incoming connection attempt on a socket.

Note

This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth.

Syntax

SOCKET accept(
  SOCKET s,
  struct sockaddr FAR* addr,
  int FAR* addrlen
);

Parameters

  • s
    [in] Descriptor identifying a socket that has been placed in a listening state with the listen function. The connection is actually made with the socket that is returned by this function.
  • addr
    [out] Optional pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family established when the socket was created.
  • addrlen
    [out] Optional pointer to an integer that contains the length of addr.

Return Value

If no error occurs, this function returns a value of type SOCKET that is a descriptor for the new socket. This returned value is a handle for the socket on which the actual connection is made.

The integer referred to by addrlen initially contains the amount of space pointed to by addr. On return, it will contain the actual length in bytes of the address returned.

If an error occurs, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Remarks

The Bluetooth server application calls accept to wait for the incoming connection. The addr must point to the SOCKADDR_BTH structure, and *addrlen must be sizeof(SOCKADDR_BTH). This structure receives the address of the connecting client.

The following example code shows how to use accept.

SOCKET s = socket (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if (s == INVALID_SOCKET) {
wprintf (L"Socket creation failed, error %d\n", WSAGetLastError ());
return;
}
SOCKADDR_BTH sab;
memset (&sab, 0, sizeof(sab));
sab.addressFamily  = AF_BTH;
if (0 != bind (s, (SOCKADDR *) &sab, sizeof(sab))) {
wprintf (L"Socket bind, error %d\n", WSAGetLastError ());
closesocket (s);
return;
}
listen (s, 5);
for ( ; ; ) {
SOCKADDR_BTH sab2;
int ilen = sizeof(sab2);
SOCKET s2 = accept (s, &sab2, &ilen);
if (s2 == INVALID_SOCKET) {
wprintf (L"Socket bind, error %d\n", WSAGetLastError ());
break;
}
wprintf (L"Connection came from %04x%08x to channel %d\n",
GET_NAP(sab2.btAddr), GET_SAP(sab2.btAddr), sab2.port);
SpinConnectionThreadsOnSocket (s2); 
}
closesocket (s);
return;

For more information about the accept function, see accept (Windows Sockets) in the Winsock reference.

Requirements

Header winsock2.h
Library Ws2.lib
Windows Embedded CE Windows CE .NET 4.0 and later

See Also

Reference

Bluetooth Application Development Functions
SOCKADDR_BTH

Concepts

Winsock Extensions

Other Resources

listen