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 using TCP Daemon and asynchronous sending



Hello,
I am looking for some advice using the NDK.  The application requires a TCP server to respond to commands sent, but in addition, i need to send data out from another thread over the same TCP connection. 

Any ideas? 

I currently have a daemon that listens for a TCP connection...this is working great.  I can connect and receive/reply to all the commands I need.  The next step is to implement this 'asynchronous' sending from another thread.

To give a general idea of what I am trying to acomplish...you send a 'start' signal over the TCP connection.  This enables another thread to periodicly send 'results' back over this TCP socket.  When the 'stop' command is received, data stops.

Thanks.

  • William,

    Which version of BIOS and NDK are you using?

    You should be able to do this using another BIOS task.  You can use a semaphore object to control when the second thread (that sends data) runs.

    So for example, you could create 2 tasks - a command server task ("server") and another task - "sender" - which sends out the data.

    The "sender" task will wait for the green light from the "server" task by calling the SEM_pend() API.

    The "server" task will flag the "sender" task by calling SEM_post().

    So, your server task has something like this (please note this is just pseudo code).  Also, since I don't know your BIOS version, I'll use the DSP/BIOS 5.x Task APIs:

    // server daemon
    Void server(cmd)
    {
        ...
        /* <insert code to listen for commands on a TCP/IP connection here> */
        ...
        /* 'cmd' is the command received */
        if (cmd == CMD_SEND) {
            /* signal the "sender" task to start sending data */
            SEM_post(dataSem);
        }
        ...
    }

    // data send task
    Void sender(ipAddress)
    {  
        ...
        /* wait until the server receives a command to send */
        SEM_pend(dataSem);

        /* <insert code to send the asynchronous data over TCP/IP here> */
        ...
    }


    Steve