Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Wi-Fi Combo

Anonymous
Not applicable

Hi,

I'm using SDK 3.5.2, ThreadX/NetX_Duo, and I run a TCP server on my device. Sometime when an incoming connexion arrives, accept won't work, and then I can't even get to the connect event callback.

I run the following code in a worker thread (triggered by the connect callback):

static wiced_result_t

eci_connect_process (void *user_data)

{

    wiced_tcp_socket_t *sock = user_data;

    unsigned char *addr = (unsigned char *) &sock->socket.nx_tcp_socket_connect_ip.nxd_ip_address.v4;

    LOG_PRINT (LOG_DEBUG, "[eci] Accepting new connection from %u.%u.%u.%u on %d\n",

               addr[3], addr[2], addr[1], addr[0], sock->socket.nx_tcp_socket_connect_port);

    wiced_result_t r = wiced_tcp_server_accept (&eci_server, sock);

    if (r != WICED_SUCCESS)

        LOG_PRINT (LOG_ERROR, "[eci] accept failed\n");

    return r;

}

And I get the following output:

LOG_DEBUG: [eci] Accepting new connection from 192.168.1.34 on 59211

Error accepting connection 2 (38)

LOG_ERROR: [eci] accept failed

I'm a bit confused because nx_tcp_server_socket_accept is not supposed to return 0x38 (NX_NOT_CONNECTED), or at least not from the NetX documentation I have from the SDK.

Did someone encounter the same issue ? Is there anyway to fix this (different that rebooting) ?

10 Replies
Anonymous
Not applicable

Partial answer has been found: wiced_tcp_server_accept doesn't listen again if the call to accept fails. Hence, once an error is encountered, I need to restart the TCP server.

But it doesn't explain why the return code isn't documented.

0 Likes
Anonymous
Not applicable

Bumping up this one. It happens quite a lot ...

vik86​ any clue about this issue ?

0 Likes
VikramR_26
Employee
10 sign-ins 10 comments on KBA 5 comments on KBA
Employee

olivierdufour​ the error code you seeing is not because of this _nx_tcp_server_socket_accept  api call, there is a check for tcp socket before that either of these calls are happening and you are seeing that.

nx_tcp_socket_bytes_available

nx_tcp_socket_receive

nx_tcp_socket_peer_info_get

Did you try increasing the timeout ?

0 Likes
Anonymous
Not applicable

I added one print in wiced_tcp_accept to get the return value of NetX function, so I don't understand why these call would change anything.

            result = nx_tcp_server_socket_accept( &socket->socket, NX_TIMEOUT(WICED_TCP_ACCEPT_TIMEOUT) );

            if ( result != NX_SUCCESS )

            {

                printf ("Accept returned %x\n", result);

                nx_tcp_server_socket_unaccept( &socket->socket );

            }

            result = netx_returns[result];

I get the following result:

LOG_DEBUG: [eci] Accepting new connection from 192.168.1.15 on 65428

Accept returned 38

LOG_ERROR: [eci] accept failed 1b66

So I don't understand the 0x38 result (unless you did a wrapper around NetX function that we can't access).

Edit: increasing timeout of accept to 1 minute didn't solve the issue.

0 Likes
Anonymous
Not applicable

Hello,

Have you solved the problem? I'm having the exact same problem, it happens randomly.

Thank you.

0 Likes
Anonymous
Not applicable

Hi,

no I didn't manage to get rid of it. I also suspect it to make WAC fail sometimes (since HTTP server uses wiced_tcp_server_accept ...).

I did a workaround, but I'm not sure it will always work.

0 Likes
Anonymous
Not applicable

Could you please share the workaround? I've been struggling with the same bug for days now.

Anonymous
Not applicable

First thing, is that even if accept fails, you need to relisten to the socket. Otherwise on first failure, no more incoming transmission will be accepted.

Then you have to retry on client side when connect fails. As far as I have seen, when local port changes, it usually works (which happens if you retry connecting).

user_2112781
Level 4
10 likes received 10 likes given 5 likes given
Level 4

Can confirm the issue as well, quite often when performing an accept I will get the 0x38 (socket closed) error code.

Using Wiced SDK 4.0.0

0 Likes
user_2112781
Level 4
10 likes received 10 likes given 5 likes given
Level 4

Issue still present with SDK 4.1.0, accept still fails randomly.

0 Likes