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.

HTTP Client for C6678L

Where can I find a sample project for running the C6678L EVK DSP as an HTTP Client "not an HTTP server". I want the DSP to send a packet to a server running at a PC. when the server receives the packet, it stores it in a database

using CCSv5.2, NDK 2.21, MCSDK 2.00.07

Regards,

 

Murad

  • Hi Murad,

    Unfortunately there is no example of running as an HTTP Client.

    However, the HTML APIs for server side responses (found in ti/ndk/nettools/html directory) can be used as an example.

    The idea is that you want to build a string that contains the HTML code you want to send, and then send that string across.

    Looking at the the API httpSendErrorHTML() (found in httpsend.c), it uses sprintf() to build the HTTP error message.

    static void httpSendErrorHTML( SOCKET Sock, int StatusCode )
    {
        char Data[80];
        int  i;

        // Build the HTML response
        sprintf( Data, "<html><body><h1>HTTP/1.0 %3d -", StatusCode );
        for(i=0;codestr[i].code && codestr[i].code!=StatusCode;i++);
        strcat( Data, codestr[i].string );
        strcat( Data,"</h1></body></html>" );

        // Send the length of the HTML response
        httpSendEntityLength(Sock, strlen(Data));

        // Send the respone data
        httpSendClientStr( Sock, Data );
    }

    You would want to build the client side command in a similar manner.

    Steve



  • Hi Steven, we have a client example in MCSDk. I beleive that it sets up a web server and that might be a good reference to start. Please advise.

    Thanks,

    Arun.

  • Thank you Steven and ArunMani,

    It seems that the Project "Client" ArunMani refering to is still assume that the DSP is the server side and the PC is the Client!!??...it has web pages to load to memory and to serve the Client side.

     

    Regards,

     

    Murad

  • Murad,

     

    The MCSDK example is using DSP as a SERVER. You are also correct in the understanding that it has webpages loaded in memory which are sent to Client on request.

    Regards,

    Bhavin

  • I am using the "Client" example of the NDK...I added a udp client task and using socket API (from "spraax4" and I can see the packets in my PC using "WireShark"...When I modified the code for TCP client, I got a Timeout error...the two codes are shown below if you can help me fix the TCP code.

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    //--------------------------------------------------------------------------

    // NDK LAB 3A: UDP sender using sockets programming

    //--------------------------------------------------------------------------

    //

    // Author: Rafael de Souza, Arnie Reynoso

    // Copyright 2007 by Texas Instruments Inc.

    //--------------------------------------------------------------------------

    #include <stdio.h>

    #include <ti/ndk/inc/netmain.h>

    #include <ti/ndk/inc/_stack.h>


    char sendBuffer[1500];

    char recvBuffer[1500];

    char *UnicastAddr = "192.168.2.101"; // PC address


    void udp_Client()

    {

        SOCKET   send = INVALID_SOCKET;    

    // Sender socket.

       

    struct   sockaddr_in sout1;         // Sender socket address structure

       

    int sentCnt;

       

    // Allocate the file environment for this task

        fdOpenSession( TaskSelf() );

       

    // Create the send socket

        send = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

       

    if( send == INVALID_SOCKET )

           

    goto leave;

       

    // Send socket: set Port = 5000, IP destination address = ANY

        bzero( &sout1,

    sizeof(struct sockaddr_in) );

        sout1.sin_family = AF_INET;

        sout1.sin_len    =

    sizeof( sout1 );

        sout1.sin_port   = htons(5000);

       

    // Bind send socket

       

    if ( bind( send, (PSA) &sout1, sizeof(sout1) ) < 0 )

            {

            printf(

    "Send: %d",fdError());

           

    goto leave;

            }

        strcpy( sendBuffer,

    "Are you there?" );

           

       

    for(;;)

        {

             sout1.sin_addr.s_addr = inet_addr(UnicastAddr);

    // PC address is the destination

             sout1.sin_port = htons(7);

    // Echo port (7) is where we want to send data


            

    // Send to PC every 5 sec

            

    do

             {

                 TaskSleep(5000);

                 sentCnt = sendto( send, sendBuffer, 15, 0, (PSA)&sout1,

    sizeof(sout1) );

             }

    while (sentCnt < 0);

            printf (

    " Message sent to ethernet \n");          

           

        }

    leave:

       

    // We only get here on a fatal error - close the sockets

       

    if( send != INVALID_SOCKET )

            fdClose( send );

       

        printf(

    "Fatal Error\n");

       

    // This task is killed by the system - here, we block

        TaskBlock( TaskSelf() );

    }

     

    ////////////////////////////////////////////////////////////////////////////////////////////////////////

    //--------------------------------------------------------------------------

    // NDK LAB 3A: UDP sender using sockets programming

    //--------------------------------------------------------------------------

    //

    // Author: Rafael de Souza, Arnie Reynoso

    // Copyright 2007 by Texas Instruments Inc.

    //--------------------------------------------------------------------------

    #include <stdio.h>

    #include <ti/ndk/inc/netmain.h>

    #includ <ti/ndk/inc/_stack.h>


    char sendBuffer[1500];

    char recvBuffer[1500];

    char *UnicastAddr = "192.168.2.101"; // PC address


    void tcp_Client()

    {

        SOCKET   Ssend = INVALID_SOCKET;    

    // Sender socket.

       

    struct   sockaddr_in sout1;         // Sender socket address structure

       

    int sentCnt;

       

    // Allocate the file environment for this task

        fdOpenSession( TaskSelf() );

       

    // Create the send socket

        Ssend = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

       

    if( send == INVALID_SOCKET )

           

    goto leave;

       

    // Send socket: set Port = 80 (HTTP), IP destination address = ANY

        bzero( &sout1,

    sizeof(struct sockaddr_in) );

        sout1.sin_family = AF_INET;

        sout1.sin_len    =

    sizeof( sout1 );

        sout1.sin_port   = htons(7);

       

    // Bind send socket

    //   if ( bind( Ssend, (PSA) &sout1, sizeof(sout1) ) < 0 )

    //       {

    //       printf("Ssend-bind: %d",fdError());

    //       goto leave;

    //       }


       

    //MQ:  Connect send socket

        sout1.sin_addr.s_addr = inet_addr(UnicastAddr);

    // PC address is the destination

        sout1.sin_port = htons(80);

    // HTTP port (80) is where we want to send data

       

    if ( connect( Ssend, (PSA) &sout1, sizeof(sout1) ) < 0 )

            {

            printf(

    "Ssend-connect: %d",fdError());

           

    goto leave;

            }

        strcpy( sendBuffer,

    "Are you there?" );

           

       

    for(;;)

        {

            

    // Send to PC every 5 sec

            

    do

             {

                 TaskSleep(5000);

                

    //http404(Ssend);

                 sentCnt = send( Ssend, sendBuffer, 15, 0);

             }

    while (sentCnt < 0);

            printf (

    " Message sent to ethernet \n");          

           

        }

    leave:

       

    // We only get here on a fatal error - close the sockets

       

    if( Ssend != INVALID_SOCKET )

            fdClose( Ssend );

       

        printf(

    "Fatal Error\n");

       

    // This task is killed by the system - here, we block

        TaskBlock( TaskSelf() );

    }

  • Hi Murad,

    Were you able to resolve your issue with the suggestions I provided previously?

    Steve