http_listen tcp_listen

Hello,

I’m trying to run the http server and another tcp socket listening in port 6000 but it seems that it can’t run at the same time.

If I put a socket listening with tcp_listen before http_init seems that de http server don’t process any request and when I put tcp_listen after http_init() I can’t connect to that socket but the http server works fine.

How I can listen to a tcp socket and use the http daemon at the same time?


   tcp_listen(&socket,6000,0,0,NULL,0);
   http_init();
   tcp_reserveport(80);


...
 while (1)
   {
         http_handler();
         conectado=0;
         endtime = MS_TIMER + (5*1000);
         if(tcp_listen(&socket,PORT_TCP,0,0,NULL,0)==0)
         {
         	printf("Ha fallado el listen antes de la espera
");
         }

         printf("Espero 5s a una conexion TCP
");

         while ((long)MS_TIMER - endtime < 0) {
         if(tcp_tick(NULL)==0)
         {
         	//printf("tcp_tick ==0 
");
         }
           
         if(sock_established(&socket))
         {
            printf("Pongo conectado a 1
");
            conectado=1;
           break;
         }


         }
         
         printf("Espera terminada
");
         if(conectado==1)
         {
               
               printf("Connection received...
");

	            do {
	               bytes_read=sock_fastread(&socket,buffer_socket,sizeof(buffer_socket));

	               if(bytes_read>0)
	               {
	                     sock_write(&socket,buffer_socket,bytes_read);
	               }
	            } while(tcp_tick(&socket));

	            printf("Connection closed...
");

            }

}


Excuse my bad English…

I have a similar problem, my need would be to put up an http server and connect with another socket to a NIST server to perform the RTC synchronization.
Did you get any advice on how to use together the http daemon and other sockets?

I guess the solution is to increase the number of TCP sockets, using the MAX_TCP_SOCKET_BUFFERS define.
That worked for me:
#define MAX_TCP_SOCKET_BUFFERS 3

From your code I further suggest to put the http_handler() function call in a separate costate than the code listening to the other socket.

Hope this helps.