lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: the problem continious with my TCP connection socket(2)


From: Oscar F
Subject: [lwip-users] Re: the problem continious with my TCP connection socket(2)
Date: Tue, 29 Sep 2009 23:58:17 +0200

more data

I´ll use this code


portTASK_FUNCTION( vProtocolRTUServer, pvParameters )
{
    //Local variables of function ==> maybe put global
    int i,maxfd,ret;
    int kk;

    struct sockaddr_in sLocalAddr[NUM_SOCKET];
    struct sockaddr_in sRemoteAddr[NUM_SOCKET];

    fd_set acceptset;



    init_dbg_rs232(66000000);
    //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;

        print_dbg(" Socket creado \n");


          //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 1 connection for socket
        if ( lwip_listen(lSocket[i],1) != 0 )
         {
           lwip_close(lSocket[i]);
         }
      }





    //Using of select function to wait for the accept connection
      FD_ZERO(&acceptset);
      print_dbg(" Sockets preprarados para entrar en el select \n");

      maxfd=0;
      kk=sizeof(sRemoteAddr[0]);

      //Add the 8 socket to wait the accept connection and then add the accept socket
      for(i=0;i<NUM_SOCKET;i++)
       {
        FD_SET(lSocket[i], &acceptset);
        if (lSocket[i]> maxfd)
         maxfd = lSocket[i];
       }



      aSocket[3]= accept(lSocket[3],(struct sockaddr*)&sRemoteAddr[3],(socklen_t *)&kk);// sizeof(sRemoteAddr[i]));
      aSocket[0]= accept(lSocket[0],(struct sockaddr*)&sRemoteAddr[0],(socklen_t *)&kk);
      aSocket[1]= accept(lSocket[1],(struct sockaddr*)&sRemoteAddr[1],(socklen_t *)&kk);
      aSocket[2]= accept(lSocket[2],(struct sockaddr*)&sRemoteAddr[2],(socklen_t *)&kk);
      aSocket[4]= accept(lSocket[4],(struct sockaddr*)&sRemoteAddr[4],(socklen_t *)&kk);
      aSocket[5]= accept(lSocket[5],(struct sockaddr*)&sRemoteAddr[5],(socklen_t *)&kk);

      aSocket[6]= accept(lSocket[6],(struct sockaddr*)&sRemoteAddr[6],(socklen_t *)&kk);
     // aSocket[7]= accept(lSocket[7],(struct sockaddr*)&sRemoteAddr[7],(socklen_t *)&kk);

 Only 6 socket are accepted, the other two fail and the program wait eternaly in the socket [6]

I don´t know what happen

Oscar




On Tue, Sep 29, 2009 at 11:06 PM, Oscar F <address@hidden> wrote:
the problem can be that i create 8 socket in different ports, an d only the thread can be use a one configuration TCP and not 8?

Thanks!
Oscar


On Tue, Sep 29, 2009 at 9:54 PM, Oscar F <address@hidden> wrote:
Hello i´m testing with this new advices.

I only want to accept the connection the first time, is for testing. the new code is this


portTASK_FUNCTION( vProtocolRTUServer, pvParameters )
{
    //Local variables of function ==> maybe put global
    int i,maxfd,ret;
    struct sockaddr_in sLocalAddr[NUM_SOCKET];
    struct sockaddr_in sRemoteAddr[NUM_SOCKET];
    fd_set acceptset;

    init_dbg_rs232(66000000);

    //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;

        print_dbg(" Socket creado \n");

          //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);
      print_dbg(" Sockets preprarados para entrar en el select \n");

      maxfd=0;

      //Add the 8 socket to wait the accept connection and then add the accept socket
      for(i=0;i<NUM_SOCKET;i++)
       {
        FD_SET(lSocket[i], &acceptset);
        if (lSocket[i]> maxfd)
         maxfd = lSocket[i];
       }

      while(1){
          // Check for received packets on configured sockets (blocking )
          ret = select(maxfd+1, &acceptset, NULL, NULL, NULL);

          if (ret > 0) //No error
            {
              //Analyze with socket receive

              for(i=0;i<NUM_SOCKET;i++)
              {
                  //socket accept
                //First thing see the connection
                if (FD_ISSET(lSocket[i], &acceptset))
                   {
                     //connection receive ==> then accept
                     aSocket[i]= accept(lSocket[i],(struct sockaddr*)&sRemoteAddr[i],(socklen_t *)sizeof(sRemoteAddr[i]));
                     num_conexiones++;

                     FD_CLR(lSocket[i], &acceptset);
                   }
              }
            }
      }

I send four thing the capture of this comunnication with customer, and two file of configuration.

In my program with emulator say me that i have connected only 6 socket, and the value os this is:
a) lsocket (create with function socket() ) values = 1,2,3,4,5,6,7,8
b) asocket(create with function accept() ) values = {1342769490, 154208563, 856240397, 172573772, 1158220114, 154143026, 808978738, 218780739}

the last value are bad no?

I don´t know what happend, i´m really lost, i don´t know what parameter change, and i don´t know if the code is OK.

Can you help me?
thank



reply via email to

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