First, thanks to all the helping hands from the group!

Weighing my options, I decided to use "real" socket programming instead of TCI_* raw APIs.

Attached is the codes of a working echo server, running on FreeRTOS.

After getting it to work, I tried to implement two echo servers on FreeRTOS.

I duplicated the codes to a different thread, on a different port, and fired it up, none worked. It seems as long as I have one socket opened, the other will not be able to work.

Any suggestion?



>>>>>>>> Working Echo Server >>>>>>>>>>>>>>>

    int lSocket;
    struct sockaddr_in sLocalAddr;

    lSocket = socket(AF_INET, SOCK_STREAM, 0);

    memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
    sLocalAddr.sin_family = AF_INET;
    sLocalAddr.sin_len = sizeof(sLocalAddr);
    sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    sLocalAddr.sin_port = TFTP_PORT;

   bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr));

   lwip_listen(lSocket, 20);


    while (1) {
        int clientfd;
        struct sockaddr_in client_addr;
        int addrlen=sizeof(client_addr);

clientfd = lwip_accept(lSocket, (struct sockaddr*)&client_addr, (socklen_t)&addrlen);
        if (clientfd>0){
            char buffer[1024];
            int nbytes;
            do{
               nbytes=lwip_recv(clientfd, buffer, sizeof(buffer),0);
                if (nbytes>0)
                lwip_send(clientfd, buffer, nbytes, 0);
           }
            while (nbytes>0 && strncmp("bye\r", buffer, 4) !=0);
            close(clientfd);
        }
    }



Date: Thu, 05 Feb 2009 19:22:05 +0100
From: "[email protected]" <[email protected]>
Subject: Re: [lwip-users] Struggling to build a TCP echo server
To: Mailing list for lwIP users <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Chen wrote:
> Could you show me how to get to the download section to get the sample
> mentioned by Simon?

http://savannah.nongnu.org/projects/lwip/ -> 'Downloads' in the upper
navigation row. After unpacking contrib, the HTTP server is in
apps/httpserver_raw/

Simon
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to