My ESP32 crashs when i call tcp_output() to flush after calling write.
I tried using tcp_nagle_disable() but it also crashs.
What i want to achieve is to send small data from tcp server on ESP32 to PC without the 200ms delay.
any help ?
This is my test code:
Code: Select all
void TcpServerTask(void *pvParam)
{
int64_t tmr = esp_timer_get_time();
char DataBuffer[1];
struct sockaddr_in tcpServerAddr, remote_addr;
unsigned int socklen = sizeof(remote_addr);
tcpServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
tcpServerAddr.sin_family = AF_INET;
tcpServerAddr.sin_port = htons(3000);
int s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {/*error allocating socket */}
int i = 1;
lwip_ioctl(s, FIONBIO, &i);
if (bind(s, (struct sockaddr *)&tcpServerAddr, sizeof(tcpServerAddr)) != 0) close(s);
if (listen (s, 2) != 0) close(s);
int CurrentSocket = -1;
while (CurrentSocket < 0) CurrentSocket = accept(s,(struct sockaddr *)&remote_addr, &socklen);
fcntl(CurrentSocket,F_SETFL,O_NONBLOCK);
//tcp_nagle_disable((tcp_pcb*)CurrentSocket);
while (true)
{
if ((esp_timer_get_time() - tmr) > 25000) // send every 25ms
{
tmr = esp_timer_get_time();
write(CurrentSocket, DataBuffer, 1);
//tcp_output((tcp_pcb*)CurrentSocket);
}
vTaskDelay(1);
}
}