tcp_server example not able to reconnect the server after disconnect

blippy
Posts: 17
Joined: Tue Jun 25, 2019 7:36 am

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

Postby blippy » 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.

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

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

Postby meowsqueak » Wed Sep 18, 2019 9:40 pm

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

blippy
Posts: 17
Joined: Tue Jun 25, 2019 7:36 am

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

Postby blippy » Wed Sep 18, 2019 10:06 pm

OK. Thanks. I'll give it a go when I have a spare ESP. All of mine are currently in-service.

blippy
Posts: 17
Joined: Tue Jun 25, 2019 7:36 am

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

Postby blippy » Tue Sep 24, 2019 2:31 pm

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.)

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

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

Postby meowsqueak » Tue Sep 24, 2019 11:03 pm

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.

blippy
Posts: 17
Joined: Tue Jun 25, 2019 7:36 am

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

Postby blippy » Wed Sep 25, 2019 8:38 am

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.

Who is online

Users browsing this forum: No registered users and 83 guests