Call this member function to associate a local address with the socket.
BOOL Bind( UINT nSocketPort, LPCTSTR lpszSocketAddress = NULL ); BOOL Bind ( const SOCKADDR* lpSockAddr, int nSockAddrLen );
- The port identifying the socket application.
- The network address, a dotted number such as "184.108.40.206".
- A pointer to a SOCKADDR structure that contains the address to assign to this socket.
- The length of the address in lpSockAddr in bytes.
Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError. The following errors apply to this member function:
- WSANOTINITIALISED A successful AfxSocketInit must occur before using this API.
- WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed.
- WSAEADDRINUSE The specified address is already in use. (See the SO_REUSEADDR socket option under SetSockOpt.)
- WSAEFAULT The nSockAddrLen argument is too small (less than the size of a SOCKADDR structure).
- WSAEINPROGRESS A blocking Windows Sockets call is in progress.
- WSAEAFNOSUPPORT The specified address family is not supported by this port.
- WSAEINVAL The socket is already bound to an address.
- WSAENOBUFS Not enough buffers available, too many connections.
- WSAENOTSOCK The descriptor is not a socket.
This routine is used on an unconnected datagram or stream socket, before subsequent Connect or Listen calls. Before it can accept connection requests, a listening server socket must select a port number and make it known to Windows Sockets by calling Bind. Bind establishes the local association (host address/port number) of the socket by assigning a local name to an unnamed socket.