WINC1500 IoT Software APIs: listen

WINC1500 IoT Software API

WINC1500 IoT Software APIs  19.5.2
WINC Software API Reference Manual

Functions

NMI_API sint8 listen (SOCKET sock, uint8 backlog)
 

Detailed Description

After successful socket binding to an IP address and port on the system, start listening on a passive socket for incoming connections. The socket must be bound on a local port or the listen operation fails. Upon the call to the asynchronous listen function, response is received through the event SOCKET_MSG_BIND in the socket callback. A successful listen means the TCP server operation is active. If a connection is accepted, then the application socket callback function is notified with the new connected socket through the event SOCKET_MSG_ACCEPT. Hence there is no need to call the accept function after calling listen.

After a connection is accepted, the user is then required to call the recv to receive any packets transmitted by the remote host or to receive notification of socket connection termination.

Function Documentation

◆ listen()

NMI_API sint8 listen ( SOCKET  sock,
uint8  backlog 
)
Parameters
[in]sockSocket 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]backlogNot used by the current implementation.
Precondition
The bind function must be called to assign the port number and IP address to the socket before the listen operation.
See also
bind accept recv recvfrom send sendto
Returns
The function returns ZERO for successful operations and a negative value otherwise. The possible error values are:

Example

This example demonstrates the call of the listen socket operation after a successful socket operation.

static void TCP_Socketcallback(SOCKET sock, uint8 u8Msg, void * pvMsg)
{
int ret =-1;
switch(u8Msg)
{
{
tstrSocketBindMsg *pstrBind = (tstrSocketBindMsg*)pvMsg;
if(pstrBind != NULL)
{
if(pstrBind->status == 0)
{
ret = listen(sock, 0);
if(ret <0)
printf("Listen failure! Error = %d\n",ret);
}
else
{
M2M_ERR("bind Failure!\n");
close(sock);
}
}
}
break;
{
if(pstrListen != NULL)
{
if(pstrListen->status == 0)
{
ret = accept(sock,NULL,0);
}
else
{
M2M_ERR("listen Failure!\n");
close(sock);
}
}
}
break;
{
if(pstrAccept->sock >= 0)
{
TcpNotificationSocket = pstrAccept->sock;
recv(pstrAccept->sock,gau8RxBuffer,sizeof(gau8RxBuffer),TEST_RECV_TIMEOUT);
}
else
{
M2M_ERR("accept failure\n");
}
}
break;
default:
break;
}
}
Generated on Thu Jan 26 2017 22:15:21 for WINC1500 IoT Software APIs by   doxygen 1.8.13