Question
· Jul 23, 2019

Server event from browser websocket connection close?

Hello,

I've got a csp page that has successfully set up a websocket connection to a Cache class. When the websocket object's close function is triggered at the browser I was expecting one of the class' methods to fire at the server. The onclose method is triggered at the browser but nothing at the server. Is a method supposed to fire at the server?

Thanks,

Dan

 

Cache for Windows (x86-64) 2015.1.4 (Build 803_6) Tue May 15 2018 12:08:36 EDT

Discussion (4)0
Log in or sign up to continue

Thanks Aohan but still nothing.

At the browser I trigger ws.close()

At the server the web socket class' Server method executes quitting with $$$OK the  OnPostServer method does not execute.

Closing the connection from the server end by invoking the web socket object's EndServer method results in the OnPostServer method executing.

Maybe of importance, the websocket is asynchronous so when triggered from the browser's .close() the Server method is not invoking the EndServer method.

I see. In asynchronous mode, you do have to call EndServer() explicitly to get the OnPostServer() method to execute. This means that you'll have to handle the client closure within your class. One way to do that is to have the client send a special message shortly before closing to indicate that a disconnect is about to happen. You can then handle that message in your WebSocket server class. Another way is to do a Read() and handle the case where $$$CSPWebSocketClosed is returned.