AnsweredAssumed Answered

3 sockets problems error in RTCS

Question asked by Wang An-Ping on Mar 25, 2010
Latest reply on Dec 14, 2012 by Colin Dawson

Enviroment: M52259 demo board with MQX3.4

 

I have tried to connect 3 sockets in a port (or even 3 sockets in 3 ports).

The first two sockets can use normally, but the last one always failed when accept.

 

Who can tell me where I'm wrong or something can be modified?

Or the idea to the failed one socket.

 

Thx,

:smileyhappy:

 

Lists attatched below:

 

 

uint_32 sock, sock1, sock2;
sockaddr_in remote_addr;
uint_16 remote_addr_len, rlen;

 

for(;:smileywink:
{
   sock = RTCS_selectall(0);
   if (sock == listensock) {
    /* Connection requested; accept it. */
    rlen = sizeof(remote_addr);
    sock = accept(listensock, &remote_addr, &rlen);
    
    if (sock == RTCS_SOCKET_ERROR) {
     printf("\naccept() failed, error 0x%lx\n",RTCS_geterror(listensock));
     printf("in while\n");
     continue;
    }
    
    if(RTCS_detachsock(sock) == RTCS_OK)
    {
     printf("accept ok\n");
    }
    else
    {
     printf("\naccept() failed, error 0x%lx", RTCS_geterror(sock));
    }
    
   }
   
   sock1 = RTCS_selectall(0);
   if (sock1 == listensock) {
    /* Connection requested; accept it. */
    rlen = sizeof(remote_addr);
    sock1 = accept(listensock, &remote_addr, &rlen);
    
    if (sock1 == RTCS_SOCKET_ERROR) {
     printf("\naccept() failed, error 0x%lx\n",RTCS_geterror(listensock));
     printf("in while\n");
     continue;
    }
    
    if(RTCS_detachsock(sock1) == RTCS_OK)
    {
     printf("accept ok\n");
    }
    else
    {
     printf("\naccept() failed, error 0x%lx", RTCS_geterror(sock1));
    }
    
 }
   
   sock2 = RTCS_selectall(0);
   if (sock2 == listensock) {
    /* Connection requested; accept it. */
    rlen = sizeof(remote_addr);
    sock2 = accept(listensock, &remote_addr, &rlen);
    
    if (sock2 == RTCS_SOCKET_ERROR) {
     printf("\naccept() failed, error 0x%lx\n",RTCS_geterror(listensock));
     printf("in while\n");
     continue;
    }
    
    if(RTCS_detachsock(sock2) == RTCS_OK)
    {
     printf("accept ok\n");
    }
    else
    {
     printf("\naccept() failed, error 0x%lx", RTCS_geterror(sock2));
    }
    
}

Outcomes