TCP connection only received 1 message then error socket problem

Dear All,

I run a TCP server on esp32. I use a packet sender program to test whether ESP32 receives multiple messages using TCP connection, I use official TCP Sock example in offfical docs of RIOT OS. I use lwIP stack to establish TCP.

The code and makefile are as follows, i tried several ways to recive multiple messages. However then a message receives after that " Error accepting new sock " is given. ;

Thanks for your help.

#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include “thread.h” #include “xtimer.h” #include “od.h” #include “net/af.h” #include “net/sock/tcp.h” #include “net/ipv6.h” #include “shell.h” #include “net/af.h” #include “net/sock/tcp.h” #include “lwip/netif.h” #define SOCK_QUEUE_LEN (1U) sock_tcp_t sock_queue; uint8_t buf[128];

/* import “ifconfig” shell command, used for printing addresses */ //extern int _gnrc_netif_config(int argc, char **argv);

static int print_ip(void) {

for (struct netif *iface = netif_list; iface != NULL; iface = iface->next) { printf("%s_%02u: ", iface->name, iface->num);

char addrstr[IPV6_ADDR_MAX_STR_LEN]; for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { if (!ipv6_addr_is_unspecified((ipv6_addr_t *)&iface->ip6_addr[i])) { printf(" inet6 %s\n", ipv6_addr_to_str(addrstr, (ipv6_addr_t *)&iface->ip6_addr[i], sizeof(addrstr))); } }

puts(""); } return 0; }

int main(void) { print_ip(); sock_tcp_ep_t local = SOCK_IPV6_EP_ANY; sock_tcp_queue_t queue; local.port = 12345; if (sock_tcp_listen(&queue, &local, &sock_queue, 1, SOCK_FLAGS_REUSE_EP) < 0) { puts(“Error creating listening queue”); return 1; } puts(“Listening on port 12345”); /*

puts(“Configured network interfaces2:”); _gnrc_netif_config(0, NULL);

*/ while (1) { // puts(“Configured network interfaces:”); // _gnrc_netif_config(0, NULL); sock_tcp_t *sock; if (sock_tcp_accept(&queue, &sock, SOCK_NO_TIMEOUT) < 0) { puts(“Error accepting new sock”); } else { int read_res = 0; puts(“Reading data”); while (read_res >= 0) { read_res = sock_tcp_read(sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT); if (read_res < 0) { puts(“Disconnected”); break; } else { int write_res; printf(“Read: “”); for (int i = 0; i < read_res; i++) { printf(”%c", buf[i]); } puts("""); if ((write_res = sock_tcp_write(sock, &buf, read_res)) < 0) { puts(“Errored on write, finished server loop”); break; } } } sock_tcp_disconnect(sock); } } sock_tcp_stop_listen(&queue); return 0; } ---------------------------------------------------- Makefile ---------------------------------------------------------

name of your application

APPLICATION = tcp-simple-server

If no BOARD is found in the environment, use this default:

BOARD ?= esp32-wroom-32

This has to be the absolute path to the RIOT base directory:


BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-leonardo
arduino-mega2560 arduino-nano
arduino-uno blackpill bluepill calliope-mini
chronos hifive1 i-nucleo-lrwan1 mega-xplained
microbit msb-430 msb-430h
nucleo-f031k6 nucleo-f042k6 nucleo-f303k8
nucleo-l031k6 nucleo-f030r8 nucleo-f070rb
nucleo-f072rb nucleo-f103rb nucleo-f302r8
nucleo-f334r8 nucleo-l053r8 saml10-xpro
saml11-xpro spark-core stm32f0discovery
stm32l0538-disco telosb
waspmote-pro wsn430-v1_3b wsn430-v1_4 z1

module as used in tests/lwip

USEMODULE += lwip lwip_ipv6_autoconfig lwip_sock_ip lwip_netdev USEMODULE += lwip_tcp lwip_sock_tcp USEMODULE += ipv6_addr USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps USEMODULE += od USEMODULE += netdev_default

additional modules for the application

USEMODULE += netstats_l2 USEMODULE += netstats_ipv6 USEMODULE += netstats_rpl USEMODULE += esp_wifi

include $(RIOTBASE)/Makefile.include

bump up. :slight_smile:

Burak Karaduman <>, 3 Ağu 2019 Cmt, 22:58 tarihinde şunu yazdı:

Hi Burak,

Hi Robin, Sorry for my behaviour, it assumed that mails are fade away when another one is sent.

  • I flash the above code to my ESP32 and from a packet sender program i send messages to port 12345 using tcp. I use the official code in RIOT docs . [1]

The edit the original code it was like that; #define SOCK_QUEUE_LEN (1U) sock_tcp_t sock_queue[ SOCK_QUEUE_LEN ];

Respect to above definition i got compile error. Then i edit it to sock_tcp_t sock_queue[ SOCK_QUEUE_LEN ]; => sock_tcp_t sock_queue; Then it complied and worked. Even if above compliation is succeed, i predicted that the information you give me about message size only one message would be received.

I expected that when i send tcp messages each 2 seconds, my server receives these messages. However only first one is received and printed the other’s cannot be received and “Error accepting new sock” is occured. I tried to tune that parameter like sock_tcp_t sock_queue[ 10 ]; but it gives compliation error. Even if it compiles, i think that it will receive 10 messages then Error accepting new sock will be occured. As result, using only the

definiation sock_tcp_t sock_queue; can i receive continious tcp messages ? How? Is there a way to reset that queue? or is there another problem in the library?



Robin <>, 4 Ağu 2019 Paz, 19:24 tarihinde şunu yazdı:

I was able to run your code on native and open/close multiple connections using netcat. Everything worked fined.

Personally, I would do the following for further debugging:

1. Check the returned error code by sock_tcp_accept.

2. Enable Debugging in the sock_tcp module and check the output.

3. Test it with native target and the software you mentioned.

4. Test it with your esp32 board and netcat.

Do you try to send multiple TCP messages over a single connection or do you open a new connection each time? Can you provide the output of your test?


Hi Burak,

Dear All, thanks for your contribution for my problem. It was ongoing issue for the esp32 and it is solved by Gunar. Esp32 runs clearly using TCP and lwip as server and client.

4 Ağu 2019 Paz 21:26 tarihinde Yegor Yefremov <> şunu yazdı: