tcp_server example not able to reconnect the server after disconnect

dhavalpatel0114
Posts: 2
Joined: Wed Oct 10, 2018 8:32 pm

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

Postby dhavalpatel0114 » Tue Nov 06, 2018 7:29 pm

attached full code for TCP SERVER + SOFTAP + STA with bugfix of connection problems after disconnect and connect again.

+ fix with able to resume socket even after disconnecting and connecting back to the station or softap.

you can switch between station and softap by changing rf_mode value.

rf_mode = 0 for softap
rf_mode = 1 for station
Attachments
tcp_server.c
(9.15 KiB) Downloaded 34 times

dhavalpatel0114
Posts: 2
Joined: Wed Oct 10, 2018 8:32 pm

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

Postby dhavalpatel0114 » Fri Nov 16, 2018 7:28 pm

Another easy solution for this problem is to close server_socket(listen_sock) when we are closing the client socket(sock).
Add the highlighted line into tcp_server_task() function.
  1.  
  2.  if (sock != -1) {
  3.             ESP_LOGE(TAG, "Shutting down socket and restarting...");
  4.             shutdown(sock, 0);
  5.             close(sock);
  6.             close(listen_sock);
  7.         }
  8.     }
  9.     vTaskDelete(NULL);
  10. }

Who is online

Users browsing this forum: No registered users and 20 guests