This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6655: How to keep connected status after calling dtask_tcp_echo

Genius 13655 points
Part Number: TMS320C6655

Hello Champs,

Customer added below NDK servers to the Client example. 

    hEcho = DaemonNew( SOCK_STREAMNC, 0, 7, dtask_tcp_proc,//dtask_tcp_echo,

                       OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hEchoUdp = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_proc,//dtask_udp_echo,
                          OS_TASKPRINORM, OS_TASKSTKHIGH, 0, 1 );//OS_TASKSTKNORM,换成更大的堆栈大小
    hData = DaemonNew( SOCK_STREAM, 0, 1000, dtask_tcp_datasrv,
                       OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hNull = DaemonNew( SOCK_STREAMNC, 0, 1001, dtask_tcp_nullsrv,
                       OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hOob  = DaemonNew( SOCK_STREAMNC, 0, 999, dtask_tcp_oobsrv,
                       OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );

She has configured the socket parameters in the first dtask_tcp_echo function,  then receive the data and send them out, at last use fdClose( s ) close this socket。

    to.tv_sec  = 5;
    to.tv_usec = 0;
    setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
    setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );

   ...

    fdClose( s );


Customer used internet assistant to transmit data. After the ethernet is connected, it will enter the dtask_tcp_echo() and close the socket in 5s, then the internet is disconnected. 

She wanted to keep the tcp in connection status, so she removed the fdclose. The host shows that the internet is connected. But the dtask_tcp_echo is only called when creating TCP socket. After transmitting the data, the dtask_tcp_echo will not be called, so it can't receive data any more. So how to resolve this problem?


Thanks.
Rgds

Shine

  • Hi,

    There is dtask_tcp_echo() implemented inside the NDK already. This is the same as customer's dtask_tcp_proc() function. I saw the NDK function has the same 5 seconds time out and close the socket connection. But we never have any issue to receive the packet after a while.

    /* Configure our socket timeout to be 5 seconds */
    to.tv_sec = 5;
    to.tv_usec = 0;
    setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
    setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );

    i = 1;
    setsockopt( s, IPPROTO_TCP, NDK_TCP_NOPUSH, &i, 4 );

    for(;;)
    {
    i = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );

    /* If we read data, echo it back */
    if( i > 0 )
    {
    if( send( s, pBuf, i, 0 ) < 0 )
    break;
    recvncfree( hBuffer );
    }
    /* If the connection got an error or disconnect, close */
    else
    break;
    }

    fdClose( s );

    /* Return "0" since we closed the socket */
    return(0);
    }

    Can she use the NDK function? Or what the difference between her function and NDK one? I saw the TI example used:

    do
    {
    rc = NC_NetStart( hCfg, NIMU_testNetworkOpen, NIMU_testNetworkClose, NIMU_testNetworkIpAddr );
    } while( rc > 0 );

    Then 

    static void NIMU_testNetworkOpen()
    {
    /* Create our local servers */
    hEcho = DaemonNew( SOCK_STREAMNC, 0, 7, dtask_tcp_echo,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hEchoUdp = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_echo,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 );
    hData = DaemonNew( SOCK_STREAM, 0, 1000, dtask_tcp_datasrv,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hNull = DaemonNew( SOCK_STREAMNC, 0, 1001, dtask_tcp_nullsrv,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hOob = DaemonNew( SOCK_STREAMNC, 0, 999, dtask_tcp_oobsrv,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );

    }

    Isn't the same use her function or NDK provided dtask_tcp_echo()?

    Regards, Eric

  • hi,

    the dtask_tcp_proc() function is same as the dtask_tcp_echo();

    I can use the NDK function, and I can perform the dtask_tcp_echo() function, but  the problem is that only when making a TCP connection can enter into this function, after receive the data or 5 seconds,the TCP connection is broken;

    I want to monitor PC data reception at any time, don't need a PC to TCP connection repeatedly, but to make TCP has been in a state of link.

    thinks.

    Amelia

  • Hi,

    I see. "after receive the data or 5 seconds,the TCP connection is broken; I want to monitor PC data reception at any time, don't need a PC to TCP connection repeatedly". There is 

    to.tv_sec = 5;
    to.tv_usec = 0;

    setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
    setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );

    I am checking the NDK team if this can be override.

    Regards, Eric

  • Hi,

    After a tcp connection is closed, either due to natural causes or due to a timeout, dtask_tcp_echo will exit. The task that creates the dtask_tcp_echo task will still remain open and listen to the listening socket. If any new connections come to the socket, then a separate socket is opened at the accept() call and the dtask_tcp_echo task will be created again.

    Can you clarify what you mean by "I want to monitor PC data reception, don't need a PC to TCP connection repeatedly, but to make TCP has been in a state of link"?

    Can you describe how you want to change this functionality?

    Thanks,
    Brandon

  • Hi,

    I mean,when the PC is connected with the dsp,  Whether the connection can be opened continuously, and when the PC is send data to dsp, an callback function can runs to told the main process that there was some data must to process.

    Now , I change the dtask_tcp_echo(), and it will never exit until the tcp connection is broken. and it always attempt to receive the data. 

        /* Configure our socket timeout to be 5 seconds */
        to.tv_sec  = 5;
        to.tv_usec = 0;
        setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
        setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
        i = 1;
        setsockopt( s, IPPROTO_TCP, NDK_TCP_NOPUSH, &i, 4 );
        s_send = s;
        Semaphore_post(sem1);
        for(;;)
        {
            i = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );
            /* If we read data, echo it back, If the connection got an error or disconnect, close */
            if( i == 0 )   //connection broken
            {
               break;
            }
            else if( i == -1 )  //receive timeout
            {
            }
            else  if( i > 0  ) //receive data and echo
            {
                if( (i = send( s, pBuf, i, 0 )) < 0 )
                {
                    i = 0;
                }
            }
        }
        recvncfree( hBuffer );
        fdClose( s );

    but now I have an other question, if the code is run into the  dtask_tcp_echo(), it means an connection is set up between the dsp and PC,A Socket is used to  transfer data for this connection, right? I can send data to PC in dtask_tcp_echo(), like the code above.

    I want send data to PC through this connetion in other task, so , I create an Semaphore to tell the other task that the connection is set up. and I give the socket to global variable(s_send = s;). 

    test_send()
    {

        char  pBuf[] = "hello,world\n";
        Uint32 i;
        Semaphore_pend(sem1, BIOS_WAIT_FOREVER);
        if( (i =send( s_send, pBuf, strlen(pBuf), 0 )) < 0 )
        {
               System_printf("send failed\n");
        }
    }
    but It always send data failed, I want know why I can't send data in other task, and how can I send data in other task through this connection.
    Thinks,
    Amelia

  • Hi,

    Did you fix your first problem?

    Yes, you are correct. Is it possible that you are closing the socket before the other task gets a chance to run and send data to the socket?

    Can you check the value of errno after the call to send fails?

    Regards,
    Brandon