Page 3 of 3

Re: tcp_server example not able to reconnect the server after disconnect

Posted: Tue Sep 17, 2019 8:01 am
by blippy
meowsqueak wrote:
Mon Sep 16, 2019 11:20 pm
Did you try the PR I linked to? I didn't have any problems with it, but my use case may be different.
Please provide the link, as it's not on this thread.

Re: tcp_server example not able to reconnect the server after disconnect

Posted: Wed Sep 18, 2019 9:40 pm
by meowsqueak
blippy wrote:
Tue Sep 17, 2019 8:01 am
meowsqueak wrote:
Mon Sep 16, 2019 11:20 pm
Did you try the PR I linked to? I didn't have any problems with it, but my use case may be different.
Please provide the link, as it's not on this thread.
It is, but here it is again anyway :)

https://github.com/espressif/esp-idf/pull/3597

Re: tcp_server example not able to reconnect the server after disconnect

Posted: Wed Sep 18, 2019 10:06 pm
by blippy
OK. Thanks. I'll give it a go when I have a spare ESP. All of mine are currently in-service.

Re: tcp_server example not able to reconnect the server after disconnect

Posted: Tue Sep 24, 2019 2:31 pm
by blippy
OK, I've had a chance to try the proposed patch (after much fiddling around with updates).

My conclusion: it fixes the big problem everyone has been having, but still contains a bug.

The bug is this: if two clients try to connect at the same time, then the second one will block (which I think is OK, that's not the problem). However, when the first one disconnects, the second one will receive a "connection reset by peer".

The problem as I see it is that

Code: Select all

close(listen_sock)
is in the wrong place. You really ought not to put it there! It closes the listening socket on disconnecting the first client, which means that anything that was connected to it at the time will be disconnected.

The code I presented in my previous post fixes that issue. (It may contain other problems, though.)

Re: tcp_server example not able to reconnect the server after disconnect

Posted: Tue Sep 24, 2019 11:03 pm
by meowsqueak
Fair enough - my workaround was a consolidation of other comments to support a single client and multiple reconnections. Two unique non-concurrent clients will need a different solution.

Re: tcp_server example not able to reconnect the server after disconnect

Posted: Wed Sep 25, 2019 8:38 am
by blippy
I think it's certainly OK to only service one connection at a time whilst keeping the others in a blocked state. Servicing multiple connections would require a much more elaborate solution, which would be too complex for the example.