Title: WebSocket close code Post by: Ecole7 on June 02, 2017, 06:37:18 PM Hello,
I would like to be able to get a valid closing code (1000) to be retrieved on the WEB client side, when I call the wsDisconnect function. The goal would be to make the difference if the closure comes from the server or the WEB client. For now I still get code 1006 which is an error. Thank you for your reply. Vincent Title: Re: WebSocket close code Post by: D.Tkalcec (RTC) on June 02, 2017, 07:52:31 PM Calling wsDisconnect closes the physical connection, which is a perfectly valid way for a Web Server to close a WebSocket connection and is correctly handled by some Web Browsers as a closed WebSocket, but ... other WebBrowsers could interpret a closed connection as an error, if there was no "CLOSE" Frame sent or received before the connection was closed.
You can always send a "CLOSE" frame to the other side by using one of the wsSend methods with the wf_Close "opcode" and an optional "payload" (see WebSocket specification for details), for example by calling Sender.wsSend(wf_Close) from inside a WebSocket event (like OnWSDataReceived). You can also implement the OnWsDataReceived event to call wsDisconnect if a wf_Close frame is received from the other side, and send a wf_Pong frame if a wf_Ping frame is received. But ... some WebBrowsers do NOT have a correct handler for the "CLOSE" frame, because of which sending a "CLOSE" frame can also give you an ERROR in some Web Browsers. Unfortunately, there is nothing I can do about the way Web Browsers implement WebSockets, so ... you will need to "tinker" and experiment a lot, if you want to make your Web Application behave the same with all major Web Browsers. Best Regards, Danijel Tkalcec Title: Re: WebSocket close code Post by: Ecole7 on June 03, 2017, 07:25:07 PM Thank you for all this clarifications that have been very helpful in solving my problem.
I modified my software and I no longer use the "closes code" and everything works very well. I am impressed by your quasi-encyclopedic knowledge in network programming. As far as I am concerned, I do not want to be pretentious in terms of my knowledge, I think that your implementation of WebSocket is the best that can be found on the market today. Greetings Vincent |