Unexpected behavior with RTCS_selectset() and accept() for TCP server socket

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unexpected behavior with RTCS_selectset() and accept() for TCP server socket

1,319 Views
tmeyer
Contributor III

Hi all.

 

I am running a Kinetis K60 Tower.

I have a simple TCP server setup to listen for incoming client connections. I am able to detect (with RTCS_selectset) and accept incoming client connections as expected for a few connections (say 10-15) . Then randomly upon attempting to connect to the server, the listening sever socket enters a state where RTCS_selectset() will immediately return indicating there is a client ready, accept return immediately with return code RTCS_SOCKET_ERROR. However when calling RTCS_geterror(server_socket) I get RTCS_OK. It is like select says a client is waiting to connect, and accept is trying but failing to accpet the connection - but not providing an error.

Furthermore when this state is entered, even shutting down and and creating a new server socket continue to behave this way.  

 

Any suggestions?

 

Thanks

Tim

 

while(retry){client_socket = RTCS_selectset(&server_socket, 1, BSP_ETHERNET_CONNECTION_TIMEOUT);  if(client_socket == RTCS_SOCKET_ERROR)   {      break;  }   else if(client_socket == server_socket)   {   client_socket = accept(server_socket, NULL, NULL);    if(client_socket == RTCS_SOCKET_ERROR)    {    int status = RTCS_geterror(server_socket);    if (status == RTCS_OK)     {     /// keeps ending up here when in bad state    }....

 

Labels (1)
Tags (1)
0 Kudos
6 Replies

577 Views
netra
Contributor IV

Hi,

Can anyone tell how to know , whether socket is shutdown or not??

after shutting down  the socket , still i am unable to create to create socket again.

It throwing error in bind().

Plz reply

Thanks,

Netra

0 Kudos

577 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport


Hi Tim,

Sometimes it is necessary to release the sockets from connections that were closed. It happened to me that I wasn't closing the sockets of clients that were leaving the server and the resources weren't been released by MQX in a big period of time and then there were no more resources to create new sockets for the new incomming connections.

Are you closing the sockets in the server side once the client left the connection?

I hope this helps.

Garabo

0 Kudos

577 Views
MPotts
Contributor III

I found the problem to be using

      shutdown(sock, FLAG_CLOSE_TX);

which does not release the internal socket context for four minutes. Using

      shutdown(sock, FLAG_ABORT_CONNECTION);

released the socket context immediately and accepted another connection.

Mark


577 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

It is good you foind the solution! Congrats!

0 Kudos

577 Views
edgarsevilla
Contributor II

Happens to me as well when I try to make a second connection to the same server

Any Ideas??

Thanks

Edgar Sevilla

0 Kudos

577 Views
MPotts
Contributor III

Hi Tim,

 

I'm afraid this is not advice, just a report of somewhat similar behavior. I am also running a simple socket server that runs ok for a while and then fails. In my case calls to RTCS_selectset on a listening socket that was working no longer signal when a connection is being attempted.

 

        while (!resetip)
        {
            rc = RTCS_selectset(&sock, 1, 1000);
            if (rc == RTCS_SOCKET_ERROR) { err = "RTCS_selectset"; goto error; }
            if (rc == 0) { continue; }
            
            /* Accept connection */
            insock = accept(sock, &inaddr, &inaddr_len);

Mark

0 Kudos