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