I'm using Ktor Server with WebSocket. When I close...
# ktor
q
I'm using Ktor Server with WebSocket. When I close a connection using the
close(CloseReason)
method, the connection is closed fine, but I never receive the text of the CloseReason in any browser. How can I make this work?
a
Do you mean you don’t see the Close frame in the
Network
tab of a web browser?
q
If I examine the close event object in Javascript console, close reason is empty on the event object, like this:
close { target: WebSocket, isTrusted: true, wasClean: true, code: 1001, reason: "", srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, … }
I would like to catch the reason in my web app, for displaying different UI states. For now the code/number will work, but I'm wondering why can't I get the reason text!?
a
As I can see from the Ktor’s code, it sends a reason for the 1001 status code. Can you share a code snippet to reproduce this issue?
124 Views