Correct Way To Close a Websocket Socket

Baldhead
Posts: 434
Joined: Sun Mar 31, 2019 5:16 am

Correct Way To Close a Websocket Socket

Postby Baldhead » Tue Sep 08, 2020 8:11 pm

Hi,

I am coding a websocket server using the esp-idf component "esp_http_server.h".

I am trying to implement a keep alive management on this server.

I would like to know the correct way to close a websocket socket once the websocket client connection is dead.

Using only this function defined on sockets.h file are sufficient, or i need to do more something ?
"static inline int closesocket(int s)"

Thank's.

Baldhead
Posts: 434
Joined: Sun Mar 31, 2019 5:16 am

Re: Correct Way To Close a Websocket Socket

Postby Baldhead » Fri Sep 11, 2020 5:40 pm

No one ?????????

Baldhead
Posts: 434
Joined: Sun Mar 31, 2019 5:16 am

Re: Correct Way To Close a Websocket Socket

Postby Baldhead » Tue Sep 15, 2020 6:52 am

Hi,

When i close a socket with "closesocket( )", the following messages appear:

E (233681) httpd: httpd_server: error in select (9)
W (233686) httpd_sess: httpd_sess_delete_invalid: Closing invalid socket 58


Any problem with this ?

Or i can keep using "closesocket( )" ?


Thank's.

ESP_cermak
Posts: 69
Joined: Thu Nov 01, 2018 8:32 am

Re: Correct Way To Close a Websocket Socket

Postby ESP_cermak » Tue Sep 15, 2020 2:50 pm

Hi baldhead,

I think you can use the below API of esp-http-server

Code: Select all

httpd_sess_trigger_close()
to close the socket fd.

Please note, that a new wss example was added to esp-idf including a very simple keep-alive mechanism. This hasn't been yet published to GitHub, but will soon appear on the master branch.

Baldhead
Posts: 434
Joined: Sun Mar 31, 2019 5:16 am

Re: Correct Way To Close a Websocket Socket

Postby Baldhead » Tue Sep 15, 2020 4:48 pm

Thank's.

But wss are client or server ?

I did a simple keep alive in my websocket server.

Apparently it's working now.

I can post the code to be included in esp-idf if you have interest.

Who is online

Users browsing this forum: Rasta_klu and 150 guests