Hello again, i have tested to accept the connection without select, and only
connect to the first connection.

aSocket[0]= accept(lSocket[0],(struct sockaddr*)&sRemoteAddr[0],(
>
> socklen_t *)sizeof(sRemoteAddr[0]));


then the next

aSocket[1]= accept(lSocket[1],(struct sockaddr*)&sRemoteAddr[1],(
>
> socklen_t *)sizeof(sRemoteAddr[1]));


but here dosen´t work and the program break!!


Can i create 8 socket TCP in a single task? maybe this is the problem

Regards
Oscar




On Mon, Sep 28, 2009 at 9:49 PM, Oscar F <[email protected]> wrote:

> Hello everybody, i have more problem with the connection TCP. The last time
> i achive to wait for accept connection. today i have the program of the
> customer (is closed) and i can´t accept the connection. I´ve installed the
> wireshark to see something but i don´t understand.
> My apllication must be accept 8 socket 3 for request and 5 for answer.
>
> The code is that, but i don´t know if the coorect configuration and the
> correct way to accept the connection.
>
> portTASK_FUNCTION( vProtocolRTUServer, pvParameters )
> {
>     //Local variables of function ==> maybe put global
>     int i,maxfd,maxfd2,numconection,ret;
>
>     struct sockaddr_in sLocalAddr[NUM_SOCKET];
>     struct sockaddr_in sRemoteAddr[NUM_SOCKET];
>
>     fd_set readset, acceptset;
>
>
>     //Create the NUM_SOCKET=8 connection to wait the accept
>     for(i=0;i<NUM_SOCKET;i++)
>     {
>           //Create the 8 socket
>         lSocket[i] = lwip_socket(AF_INET, SOCK_STREAM, 0);
>         if (lSocket[i]<0)
>          return;
>
>
>           //Bind to this socket
>           memset((char *)&sLocalAddr[i], 0, sizeof(sLocalAddr[i]));
>         sLocalAddr[i].sin_family = AF_INET;
>         sLocalAddr[i].sin_len = sizeof(sLocalAddr[i]);
>         sLocalAddr[i].sin_addr.s_addr = htonl(INADDR_ANY); //!!!!CUIDADO
> SINO VALE CUALQUIER DIRECCION CAMBIAR!!!!
>         sLocalAddr[i].sin_port = PortConnection[i]; //Ports of the table
>
>
>         if (lwip_bind(lSocket[i],(struct sockaddr *)&sLocalAddr[i],
> sizeof(sLocalAddr[i])) < 0)
>          {
>            //Error. Close the socket
>            lwip_close(lSocket[i]);
>          }
>
>         //Listen to the 8 socket.Maximum 10 connection for socket
>         if ( lwip_listen(lSocket[i],10) != 0 )
>          {
>            lwip_close(lSocket[i]);
>          }
>       }
>
>       //Using of select function to wait for the accept connection
>       FD_ZERO(&acceptset);
>       FD_ZERO(&readset);
>
>       maxfd=0;
>       maxfd2=0;
>       numconection=0;
>       //Add the 8 socket to wait the accept connection
>       for(i=0;i<NUM_SOCKET;i++)
>        {
>         FD_SET(lSocket[i], &acceptset);
>         if (lSocket[i]> maxfd)
>          maxfd = lSocket[i];
>        }
>
> //The application wait here. Never accept any connection.
>
>       do{
>           // Check for received packets on configured sockets (blocking )
>           ret = select(maxfd+1, &acceptset, NULL, NULL, NULL);
>
>           if (ret > 0) //No error
>             {
>               for(i=0;i<NUM_SOCKET;i++)
>               {
>                  if (FD_ISSET(lSocket[i], &acceptset))
>                   {
>                    //connection receive ==> then accept
>                    aSocket[i]= accept(lSocket[i],(struct
> sockaddr*)&sRemoteAddr[i],(socklen_t *)sizeof(sRemoteAddr[i]));
>                    if(aSocket[i]>0)
>                     {
>                        if (i<3)
>                        {
>                         FD_SET(aSocket[i], &readset); //Add the three
> socket to wait for the receive data
>                         if (aSocket[i]> maxfd2)
>                          maxfd2 = aSocket[i];
>                        }
>                        numconection++;
>                     }
>                    else
>                       lwip_close(aSocket[i]);
>
>                    //FD_CLR(lSocket[i], &acceptset);
>                   }
>                 }
>               }
>           else
>            {
>                CloseConnectionPC(aSocket,lSocket );
>                return;
>            }
>       }while ( numconection <NUM_SOCKET );
>
>
> Can you help me. I´m lost.
>
> thank
> Oscar
>
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to