Hi All,
I am working with esp32 in station mode as a TCP server. I want 6 TCP server to run simultaneously. But the problem is i see 7 tcp clients connect through the hercules terminal. In listen() i have kept the backlog value as -1. But still the 7 client connects.
In my while loop am only calling accept() 6 times. I dont see any data for the 7 client unless i disconnect one of the 6 clients connected to my servers. I dont want the 7th client to get connected.
Any help is appreciated.
Problem with ESP32 TCP Server
Re: Problem with ESP32 TCP Server
How can we help if we cant see your code ?
Re: Problem with ESP32 TCP Server
@mike Thanks for your concern.
Here is the code i have written
listener = socket(addr_family, SOCK_STREAM, ip_protocol);
bind(listener, (struct sockaddr *)&destAddr, sizeof(destAddr));
if (listen(listener, -1) == -1)
{
ESP_LOGI(TAG_TCP, "Listen ERROR! ");
}
while(1)
{
if(total_clients_accepted < 6)
{
addrlen = sizeof remoteaddr;
newfd = accept(listener,(struct sockaddr *)&remoteaddr,&addrlen);
if (newfd == -1)
{
ESP_LOGI(TAG_TCP, "Accept New Connection");
}
else
{
FD_SET(newfd, &master);
if (newfd > fdmax)
{
fdmax = newfd;
}
ESP_LOGI(TAG_TCP, "New connection from %s on socket %c\n",inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&remoteaddr),remoteIP, INET6_ADDRSTRLEN),newfd);
total_clients_accepted += 1;
ESP_LOGI(TAG_TCP, " Total Clients Connected = %d", total_clients_accepted);
}
}
}
Please let me know.
Also i have set the setsockopt() for internal keepalvies, but it is also not working.
int keepAlive = 1;
int keepInterval = 1000;
setsockopt (listener, IPPROTO_TCP, TCP_KEEPALIVE, (void*) &keepAlive, sizeof (keepAlive));
setsockopt (listener, IPPROTO_TCP, TCP_KEEPINTVL, (void*) &keepInterval, sizeof (keepInterval));
Please let me know what needs to be corrected.
Here is the code i have written
listener = socket(addr_family, SOCK_STREAM, ip_protocol);
bind(listener, (struct sockaddr *)&destAddr, sizeof(destAddr));
if (listen(listener, -1) == -1)
{
ESP_LOGI(TAG_TCP, "Listen ERROR! ");
}
while(1)
{
if(total_clients_accepted < 6)
{
addrlen = sizeof remoteaddr;
newfd = accept(listener,(struct sockaddr *)&remoteaddr,&addrlen);
if (newfd == -1)
{
ESP_LOGI(TAG_TCP, "Accept New Connection");
}
else
{
FD_SET(newfd, &master);
if (newfd > fdmax)
{
fdmax = newfd;
}
ESP_LOGI(TAG_TCP, "New connection from %s on socket %c\n",inet_ntop(remoteaddr.ss_family,get_in_addr((struct sockaddr*)&remoteaddr),remoteIP, INET6_ADDRSTRLEN),newfd);
total_clients_accepted += 1;
ESP_LOGI(TAG_TCP, " Total Clients Connected = %d", total_clients_accepted);
}
}
}
Please let me know.
Also i have set the setsockopt() for internal keepalvies, but it is also not working.
int keepAlive = 1;
int keepInterval = 1000;
setsockopt (listener, IPPROTO_TCP, TCP_KEEPALIVE, (void*) &keepAlive, sizeof (keepAlive));
setsockopt (listener, IPPROTO_TCP, TCP_KEEPINTVL, (void*) &keepInterval, sizeof (keepInterval));
Please let me know what needs to be corrected.
Who is online
Users browsing this forum: No registered users and 93 guests