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.

CCS/TMS320C6670: TCP server with NDK library

Part Number: TMS320C6670

Tool/software: Code Composer Studio

Hello!

I use DSP board with TMS320C6670 and NDK-lib for ethernet.

Using the HelloWorld example, I implemented UDP protocol.

But now the challenge is to create a TCP server based on the NDK library.

Can you give an example of creating such a server? Because I have some problems with the implementation of such a server using the NDK library.

Thanks.

Regards. Alexander

  • Hi,

    Check the following E2E thread:
    e2e.ti.com/.../591323

    Best Regards,
    Yordan
  • I tracked this conversation and all the links in it.
    Unfortunately , there is no TCP / IP server example in these links. Only UDP.
    The dtask_tcp_echo function is mentioned, but it is not provided anywhere.

    Regards, Alexander
  • Hi,

    There is no TCP server example provided, you could use the nimu examples as reference. And use the NDK Developer's Guide (www.ti.com/.../spru524k.pdf ), section 5.4 TCP/UDP Server Daemon Support to create your app.

    Also the NDK FAQ: processors.wiki.ti.com/.../Network_Developers_Kit_FAQ along with the Processor SDK RTOS User Guide: software-dl.ti.com/.../index_Foundational_Components.html should be of use to you.

    Best Regards,
    Yordan
  • Yes, I understand. I did it.
    Thank you.
    I wanted to clarify the details, so I was looking for an example.
    Because I did not quite understand the features of the NDK library for TCP-protocol. For example, in terms of the work of the functions accept, read, send in blocking and non-blocking modes.
    But I will try to figure it out myself.
    Thank you.

    Regards, Alexander
  • Sorry!  But I have problem with NDK TCP Server so far.

    I try use TCP/UDP Server Daemon Support (as in spru524 section 5.4)

    as in the example from the document:

    hEcho = DaemonNew( SOCK_STREAMNC, 0, 7, dtask_tcp_echo, OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 ) ;

    and  callback func :

    int dtask_tcp_echo( SOCKET s, UINT32 unused )
    {
    struct timeval to;
    int I;
    char *pBuf;
    HANDLE hBuffer;
    (void)unused;
    // 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, 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);

    }

    As stated in the document (spru524), this is sufficient. If client try to establish a connection , the function dtask_tcp_echo()  will be called.

    But no!

    In my client programm (PC, Wind10) I'm try :

    sock = socket(AF_INET, SOCK_STREAM, 0);

    ...

    code = connect(sock, (struct sockaddr *) &servAddr, sizeof(struct servAddr);

    if (code <0)

    {

    // ERROR

    ...

    }

    ...

     

    Structure servAddr is correct! 

    But ther is no connection.

    code = -1 (ERROR)

    And my callback func dtask_tcp_echo() in DSP no called. 

    What's the matter?

    Perhaps from the server side I need to run listen() and accept()?   But spru524 sec5.4  says that Daemon does it himself. Or no?

    Answer please.

    Regards, Alexander

     

     

  • Hi Alexander,

    Perhaps from the server side I need to run listen() and accept()?   But spru524 sec5.4  says that Daemon does it himself

    Yes, this should be the case. Let me check this further.

    Best Regards,
    Yordan

  • I tried to use  listen() and accept(). But it does not work.

    First of all, this funcs needs a discriptor of socket (SOCKET socket) as a argument . And Daemon does not return it in

    hEcho = DaemonNew( SOCK_STREAMNC, 0, 7, dtask_tcp_echo, OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 ) ;.

    hEcho  is the idetificator of the Daemon object, not the socket discriptor

    Daemon return the socket discriptor in callback func

    int dtask_tcp_echo( SOCKET s, UINT32 unused )

    But for callback func be called there listen() and accept() must be done.

    And here is the questions. Where are these functions called? And is it generally called somewhere?

    And more question.

    What is the difference in calling DaemonNew( ) for TCP-server and for TCP-client?

    Because, for a TCP-client I need to call a connect() function  instead of functions listen() and accept() . Or Daemon must do it itself.

    But does Daemon do it?

     

    Regards, Alexander

  • Hi,

    C6670 is not supported in Processor SDK RTOS anymore, but for the NDK part, you can use the same. For C6678, there is NIMU_emacClientExample_EVMC6678C66BiosExampleProject. This one opened the daemons:

    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 );

    ...}

    Among them dtask_tcp_echo is what you are looking for. This project can either run DHCP or static IP. Then you can use the NDK packages\ti\ndk\winapps to test it. The recv, send and echoc use TCP/IP protocol. I just tested it, they all worked. You can set break point in daemon(), listen(), NDK_accept(), NDK_listen(), etc... functions to see how they are called inside NDK package.

    Regards, Eric

  • If I understand correctly, functions listen(), NDK_accept(), NDK_listen(), etc... are called inside the daemon. 

    I myself should not call them anywhere

    All I have to do is 

    // Create my local server
    hEcho = DaemonNew( SOCK_STREAMNC, 0, 7,   dtask_tcp_echo,   OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );

    /// Determine my callbackFunc

    int dtask_tcp_echo( SOCKET s, UINT32 unused )
    {  
    ....    }

    and more I must to turn on and describe TCP-service in configuration file xxxx.cfg

    That all what needs.

    Well. 

    This scheme works well and is already used by me, but for UDP-protocol:

    hEchoUdp = DaemonNew( SOCK_DGRAM, 0, 7,   dtask_udp_echo,    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 );

    ...

    int dtask_udp_echo( SOCKET s, UINT32 unused )
    {

    ....

    }

    I have been using this UDP for a long time.

    But TCP-server does not work. There is no connection with TCP-client. Although I use the TCP-client that works well with other TCP-servers.

    Could this be due to the fact that I have a processor 6670 (not 6678)?

    And...

    There

    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 );

    ...}


    How do the daemon knows that it's needs to open the TCP-server, not the TCP-client and to use internally  functions listen() and accept(), not connect() ?

    And is it even possible to build a TCP-client through a daemon?

    Regards, Alexander

  • Hi,

    NDK is independent of the hardware level. So using C6670 and C6678 should be the same. I tried the C6678 yesterday for the client example, this worked well for me for both UDP and TCP, the TCP you can test the send, recv and echoc. For UDP, you can test with helloworld and testudp.

    You are right those accept, listen, connect are called inside daemon, your application doesn't need to call them.

    For "

    How do the daemon knows that it's needs to open the TCP-server, not the TCP-client and to use internally  functions listen() and accept(), not connect() ?

    And is it even possible to build a TCP-client through a daemon?"

    Let me check with me colleague.

    Regards, Eric

  • The daemon is a server. It cannot be a client (e.g. it never calls connect()). 

    Todd