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.

NDK + TCP periodic sending

Hello,

my program is based on client demo aplication and add TCP server like daemon. Server works good as echo server. I can receive packet, parse it and return answer by TCP, it already works fine. But... is it possible to send TCP packet  from anywhere in my program? For example  sending from periodic task - I can create periodic task that can call each 1sec, but function SENDTO doesnt work here. Or send TCP packet from HWI - same problem SENDTO doesnt work. So, is it possible to call sendto function from another task - not directly from server? I think, it must works beacuse it is realy basic function - sending TCP packet if I want.....

Thank you for quick response

VS

  • Hi,

    Using the NDK you will be able to send TCP/IP messages from any where in your program.

    but you have to define the other peer receiving socket get it up to work and listen to your tcp/ip packet, then connect to it from your DSP code and then send data to it.

    in the Benchmarking folder, the nonCopyTCPTester example, look at the "void sendclient()" function

    I tried this with UDP and it worked, I guess for TCP it will be simpler.

    Hope this helps

    Have you tried to boot using EMAC?

     

    Regards,

    Maroun Farah

     

  • Hi,

    no I wil not use for EMAC booting. I have tried to send TCP packet with text string  to PC application(client). after DSP start(server). And then DSP must sending periodically - for example each 1s. So i need to add sendto function into timer service. Timer service is no problem but when I tried to add sendto here, this sendto doesnt stil work. You wrote that you tried it with UDP sending. Is it possible to obtain yout example code for udp sending? Than i will try to modify it for tcp....

    thanks

  • Hi,

    are  the client example working and Testee benchmarking example working? have you tried to compile and run  their recv.c and send.c host application?

    I my slef haven't tried to send information from a timer task , I did send from the DAOMON tasks created by the NDK when a socket connection is established.

    I suggest that you do the folowing:

    1. define a socket that can be used by the DAOMON and by you timer service.

    2. define a DAOMON that accepts connections.

    3. once there is a connection yout DAOMON will accept it and open a socket to support the connecting client

    4. now use this socket in your code, I am not sure if the DAOMON mu stay active, (if so try to use a semaphore to keep the DAOMON and the socket alive) until the reuest is servioced by your timer service.

    5. in your timer service you can check the socket / or any request connection or indication flag you wish to use, if there is a request and there is a valid socket then send through the socket. Remember there are timeouts at the serer side socket.

    Remember because the DSP is the server, then the communication is asynchronous at the DSP side, you can synchronise only within the timeout of the socket at the host side.

    I am using the following to send from the DSP side:

    int dtask_tcp_datasrv( SOCKET s, UINT32 unused )
    {
        struct timeval to;
        int            i,size;

        (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 ) );
     printf("dtask_tcp_datasrv started \n");
        i = 1;
        setsockopt( s, IPPROTO_TCP, TCP_NOPUSH, &i, 4 );

        for(;;)
        {

    //the following code receives from the inut socket, You don't have to use it
            // There is data available on the active connection  
            i = (int)recv( s, (char *)&size, sizeof(int), 0 );

    // ---- Special Code for Big Endian Build ----
    #ifdef BIGENDIAN
            // Size comes in as little endian!
            // We need to convert it
            size = ((size>>24)&0xFF) + ((size>>8)&0xFF00) + ((size<<8)&0xFF0000) + (size<<24);
    #endif
    // -------------------------------------------

     

    //you can directly try to send the data to the connecting host once the socket is alive and working

            if( i==sizeof(int) )
            {
                if( send( s, (char *)&size, size, 0 ) < 0 )
                    break;
            }
            else
                break;
        }

        // Note in dtask_tcp_echo() we close the socket at this
        // point. Here we'll leave it open to test the daemon.

        // Return "1" since the socket is still open
     printf("dtask_tcp_datasrv ended \n");
        return(1);
    }

     

     

    Hope this helps,

    Maroun

  • Hi,

    sorry for long response. Iam very grateful to your help for me. In your example which you posted here the send function is still inside  int dtask_tcp_datasrv( SOCKET s, UINT32 unused ). That mean I am not able to call send function from anywhere in my program. I need somethiing like this:

    void PeriodCalling_100ms(void){

    send (s,"KeepAlive\n",10,0);     //each 100ms send this string over TCP seassion which defined in external variable 's'. S can be defined in the first calling of dtask_tcp_dataserv

    }

    So my question is still actual! How can I send data over ethernet (TCP seassion-DSP is server) anywhere in my program??? Not  only in function which is called by ethernet frame receiving (dtask_tcp_dataserv) like in all examples from TI for their NDK.

    Iam sure that the NDK must supported this!

    thanks for response

  • I am face with the same problem.

    I also want to use "send()" function in anther task.
    When I make these socket variable like "stcp,stcpactive" be  global, it seems that NDK doesn't work.
    It can't work correctly,and after recieve data ,it seems dead at all.

    Can SOCKET variable be global?
    Can I use it like other global variable ?

    Is it because that file descriptor set is belong with taskself so it can be used in other task?

    If I want to send data in other task ,how can I do?

    Thank you for your help.

     

  • Hi,

    Since I had to write my own EMAC bootloader, (the one supplied sitting in the ROM was very difficult to work with) and since that the NDK driver is very difficult to work with when trying to add code for it due to cache and memory management complexities, also due to through put.

    I decided to write my own thin ethernet driver sending udp packets and/or raw ethernet to the user interface,

    I got about 900Mbps throughput on a 1gigabit, and life is much easier since then

    This way you can send a packet from any where in the application, however you will need to understand how to fill up packets with data and how the emac/mdio peripheral realy work.

    you will need: emac example comming with the EVM, at the PC side winshark to analyse the packets, and preferably wpdpak library to filter and acquire the packets instead of winsock. 

    Regards

    M.Farah

  • Hi,

    mr. Farah recomends me deep studies about NDK. I am disapointed by this function is not implemented in NDK.

    There is a realy no easy way, how to call send function anywhere???

    thanks to all

     

  • Hello,

    I too am facing the same issue of sending the data thro sendto() from anywhere in the program.

    TI guys, kindly help us resolve this issue . I see that this issue has been pending from a long time.

    Regards

    Santosh

  • Hello All.

    Can any one please help me with sendto() API of NDK to be called from anywhere in the program.

    Please help.

     

  • Facing the same problem, is there already a solution found? I am able to send out packets only in the call back fkt from the daemon server.... this s****! Very frustrating....

  • Ok... ignore this! I solved the problem by deactivating my antivir firewall!