TCP socket connection fail when webserver is active

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

TCP socket connection fail when webserver is active

ソリューションへジャンプ
1,761件の閲覧回数
michelekorell
Contributor II

Hello

Now i'm using mqx 4_0_2, with cw10.4. When i try to connect with a PC to the tcp socket on a twr-k60f120m with a webserver active the connection works only the half of the time. When i deactivate the embedded webserver it's work great.

I have searched on differents discussion on this forum and after trying to augment the tcp socket connection limits the problem doesn't disappear.

Here is the code that get the incoming socket connection:

//Block here until they are socket activity

sockSet[0] = mySocket->listenSock;

sockSet[1] = mySocket->sock;

sock = RTCS_selectset(sockSet, 2, 0);

if(sock ==mySocket->listenSock)

{

...

//Test incoming connection

if(mySocket->sock == 0)

{

  mySocket->sock = accept(mySocket->listenSock, &mySocket->remoteAddr, &mySocket->remoteAddrLen);

  ...

}

...

}


I don't know if they are any error in these connection logic or if are something to activate in the user_config to run the webserver and a socket connection together.

UPDATE:

When the connection doesn't work, in the RTCS socket summary i see that my socket is connected and it appear a socket with ground state. When the task work well, the socket in ground state doesn't appear.

RTCS_SockProblem.PNG.png

Any one can help me?

Thanks Smiley Happy

ラベル(1)
1 解決策
1,490件の閲覧回数
michelekorell
Contributor II

Workaround found:

when i wait for activity and my socket is not connected I call the accept() function that block until the connection of a client. Then I wait on RTCS_selectset() to get activity on my target socket. When socket is closed I return on accept() function. If new activity on listen socket is detected i do nothing.

if(mySocket->socket == 0)

{

     mySocket->sock = accept(mySocket->listenSock, &mySocket->remoteAddr, &mySocket->remoteAddrLen);

...

}

...

sock = RTCS_selectset(sockSet, 2, 0);

if(sock == mySocket->sock)

{

     length = recv(sock, mySocket->receiveBuffer, mySocket->receiveBufferSize, 0);

...

}

else if(sock == RTCS_SOCKET_ERROR)

{

//Handle error

...

}

else

{

//Handle other socket activity

}

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
1,491件の閲覧回数
michelekorell
Contributor II

Workaround found:

when i wait for activity and my socket is not connected I call the accept() function that block until the connection of a client. Then I wait on RTCS_selectset() to get activity on my target socket. When socket is closed I return on accept() function. If new activity on listen socket is detected i do nothing.

if(mySocket->socket == 0)

{

     mySocket->sock = accept(mySocket->listenSock, &mySocket->remoteAddr, &mySocket->remoteAddrLen);

...

}

...

sock = RTCS_selectset(sockSet, 2, 0);

if(sock == mySocket->sock)

{

     length = recv(sock, mySocket->receiveBuffer, mySocket->receiveBufferSize, 0);

...

}

else if(sock == RTCS_SOCKET_ERROR)

{

//Handle error

...

}

else

{

//Handle other socket activity

}

0 件の賞賛
返信
1,490件の閲覧回数
Martin_
NXP Employee
NXP Employee

From your description, it seems like accept() creates a new socket OK, but subsequent processing leads to an error. Accept() may return RTCS_SOCKET_ERROR and then you can call RTCS_geterror() on the listening socket to determine the cause. Errors are listed in rtcs_err.h.

0 件の賞賛
返信
1,490件の閲覧回数
michelekorell
Contributor II


Hello, thanks for the quick reply.

I have added somes debug message and I notice that when the connection doesnt work, the task is blocked into the accept(...).

here are the complete code of accept function:

if (mySocket->sock == 0) {   printf("\nAccept new socket\n");   mySocket->sock = accept(mySocket->listenSock, &mySocket->remoteAddr, &mySocket->remoteAddrLen);   printf("\nAccept new socket on: %d\n",mySocket->sock);   if (mySocket->sock == RTCS_SOCKET_ERROR)   {     printf("\naccept() failed, error 0x%lx", RTCS_geterror(mySocket->listenSock));     if (shutdown(mySocket->sock, FLAG_CLOSE_TX) != RTCS_OK)     {       printf("\nfailed shutdown socket (sock == 0)"); //, buf);     }     else     {       printf("\nDISCONNECTED");       mySocket->sock = 0;     }     //continue;   }

  // Send back a quote:   printf("\nCONNECTED"); }

If the client disconnect and connect the task continue to work. Now I try to debug around the task execution.

0 件の賞賛
返信