![]() |
WINC1500 IoT Software APIs
19.5.2
WINC Software API Reference Manual
|
Functions | |
NMI_API sint8 | bind (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen) |
Detailed Description
Asynchronous bind function associates the provided address and local port to the socket. The function can be used with both TCP and UDP sockets it's mandatory to call the bind function before starting any UDP or TCP server operation. Upon socket bind completion, the application will receive a SOCKET_MSG_BIND message in the socket callback.
Function Documentation
◆ bind()
- Parameters
-
[in] sock Socket ID, must hold a non negative value. A negative value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in. [in] pstrAddr Pointer to socket address structure "sockaddr_in" sockaddr_in [in] u8AddrLen Size of the given socket address structure in bytes.
- Precondition
- The socket function must be called to allocate a socket before passing the socket ID to the bind function.
- Returns
- The function returns ZERO for successful operations and a negative value otherwise. The possible error values are:
- SOCK_ERR_NO_ERROR Indicating that the operation was successful.
- SOCK_ERR_INVALID_ARG Indicating passing invalid arguments such as negative socket ID or NULL socket address structure.
- SOCK_ERR_INVALID Indicate socket bind failure.
Example
This example demonstrates the call of the bind socket operation after a successful socket operation.
struct sockaddr_in addr;
SOCKET udpServerSocket =-1;
int ret = -1;
if(udpServerSocket == -1)
{
if(udpServerSocket >= 0)
{
addr.sin_family = AF_INET;
addr.sin_port = _htons(1234);
addr.sin_addr.s_addr = 0;
if(ret != 0)
{
printf("Bind Failed. Error code = %d\n",ret);
close(udpServerSocket);
}
}
else
{
printf("UDP Server Socket Creation Failed\n");
return;
}
}
Generated on Thu Jan 26 2017 22:15:21 for WINC1500 IoT Software APIs by
