lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Struggling to build a TCP echo server


From: Francois Bouchard
Subject: Re: [lwip-users] Struggling to build a TCP echo server
Date: Fri, 13 Feb 2009 12:30:18 -0500

Hi Chen,
 
I'm working on a similiar project : basic echo server with FreeRTOS, but me I use the netconn_* API.  Right now it accepts only one connection, but I must program the server to allow multiple socket simultaneously, like you need to.
 
By the way i'm very new into socket programming.
 
I did'nt tried anything yet but thought of ways to acheive that:
  • bind every port/address you need, then listen to them.
  • create a task that waits for client to connect;
  • once a client connected, this task should start/resume the echo server task (which shall be the same code for every connections)
  •  Try to share and manage lwIP ressource between all tasks.
    good luck
 
Francois
 
 
 
----- Original Message -----
From: Chen
Sent: Friday, February 13, 2009 10:50 AM
Subject: Re: [lwip-users] Struggling to build a TCP echo server

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: "address@hidden" <address@hidden>
Subject: Re: [lwip-users] Struggling to build a TCP echo server
To: Mailing list for lwIP users <address@hidden>
Message-ID: <address@hidden>
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
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users

reply via email to

[Prev in Thread] Current Thread [Next in Thread]