Answering my own question here..
This error shows up if the socket is accidentally closed (which is what happened to me).
By the way, this code works in terms of creating a binding socket. Just be aware that some of the send() recv() calls may be blocking, so you have to make them non-blocking
k_sleep(K_MSEC(200));
s_sock=socket(AF_INET,SOCK_STREAM,0);
if(s_sock<0)
{
LOG_ERR ("**********Fail to create socket...");
//return 0;
}
else
LOG_ERR ("****************Binding... s_sock %d", s_sock);
k_sleep(K_SECONDS(2));
s_addr.sin_family=AF_INET; // 1
//serAdd.sin_addr.s_addr=htonl(INADDR_ANY);
s_addr.sin_addr.s_addr=htonl(INADDR_LOOPBACK);
s_addr.sin_port=htons(6060);
if(bind(s_sock,(struct sockaddr *)&s_addr,sizeof(s_addr))==0)
{
LOG_ERR ("============Binding succed!...");
}
else
{
LOG_ERR ("=============Binding failed...");
}