lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Help,V1.3.2,socket API, how to deal with multi client?


From: megatron
Subject: [lwip-users] Help,V1.3.2,socket API, how to deal with multi client?
Date: Mon, 28 Mar 2011 04:36:40 -0700 (PDT)

hello everone:
   I use FreeRTOS and socket API,LWIP is V1.3.2, the cpu is NXP1768,which is
a 

CORTEX M3 micocontroler. My cpu is a server. The remote client is Windows 

Application. If there is only  one client ,connect-communicate-disconnect,it 

works well.But If there are two or more client, connected to my server,then  

my server will soon stop response,no client can connect anymore.  I tried
two 

method:
1. listen(iSock,0),but is doesn't work.still more than one client can 

connected.
2. closesocket(tsock) after send().But after several times the closesocket 

funcion doesn't return.

How can I do with this situation that there are more than one client?  Can I 

set lwip to allow only one client connected at one time? Or there are
mistakes in my source code?

Thanks alot!


My code:

void Server_task(void *param)
{
  int iSock;
  struct sockaddr_in server,client;
  int  tsock;
  int  step;
  int  err;
  int len;
  INT32U  tt;
  
  step = 1;
  
  iSock = socket(AF_INET, SOCK_STREAM, 0);
  server.sin_family = AF_INET;
  server.sin_port = htons(6000);
  server.sin_addr.s_addr = htonl(INADDR_ANY);
  tsock = bind( iSock, (struct sockaddr *)&server, sizeof(server));
  tsock = listen(iSock,5);          
  
  while(1)
  {
    switch(step)
    {
      case 1:
        tt = sizeof(client);
        tsock = accept(iSock,(struct sockaddr*)&client,&tt);
        step = 2;
        break;
      case 2:
        len = recv(tsock,recvbuf,1500,0);  
        if(len <= 0)
        {  
          closesocket(tsock);
          step = 1;
        }
        else 
        {  
          /* do some thing */
          len = send(tsock,recvbuf,len,0);
        }
        break;
    } //end of switch
  }  //end of while(1)
}

-- 
View this message in context: 
http://old.nabble.com/Help%2CV1.3.2%2Csocket-API%2C-how-to-deal-with-multi-client--tp31257203p31257203.html
Sent from the lwip-users mailing list archive at Nabble.com.




reply via email to

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