Reputation: 346
Hello im realy new to Websockets, i build a webchat with Websockets and a PHP socket server. To store userdata i use PHP-Sessions.
I want to unset the session when the user disconnects. When Websocket onclose is triggerd im not able to send a message (Server is allready closed or in close state) to the Server.
Is there a nice way to send from client to server before onclose happens?
thanks a lot
Upvotes: 0
Views: 4416
Reputation: 35965
It depends.
You can send something right before closing the window/tab with the onbeforeunload event. Or if you have a deterministic close function in your app like buttons for "Disconnect", "Close", "Connect somewhere else"... etc..., you will have to ensure you send whatever you want before closing.
But there is nothing like "onbeforeclose": https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
Upvotes: 2