[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] the problem continious with my TCP connection socket
From: |
Oscar F |
Subject: |
[lwip-users] the problem continious with my TCP connection socket |
Date: |
Mon, 28 Sep 2009 21:49:51 +0200 |
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
lwipopts.h
Description: Binary data
conf_eth.h
Description: Binary data
ProtocolRTU.c
Description: Binary data
ProtocolRTU.h
Description: Binary data
- [lwip-users] the problem continious with my TCP connection socket,
Oscar F <=
- [lwip-users] Re: the problem continious with my TCP connection socket, Oscar F, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Kieran Mansley, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Oscar F, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Kieran Mansley, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Oscar F, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Oscar F, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Kieran Mansley, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Oscar F, 2009/09/29
- Re: [lwip-users] the problem continious with my TCP connection socket, Kieran Mansley, 2009/09/30
- Re: [lwip-users] the problem continious with my TCP connection socket, Oscar F, 2009/09/30