How would you force close a websocket after a timeout? #677
Answered
by
e3dio
Zanoro9000
asked this question in
Q&A
Replies: 1 comment 1 reply
-
app.ws('/', {
open: ws => {
ws.timeout = setTimeout(() => ws.close(), timeout)
},
close: ws => {
clearTimeout(ws.timeout)
}
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Zanoro9000
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an authentication process for devices and would like that to expire every specified period of time (e.g. 24hrs after they connected). I don't see any way to close a single connection from outside of a message handler.
I would prefer not to have to put the work of closing on the client side or to have to restart the whole server. I could invalidate their auth status in the socket and then on their next message close them but wondering if there is an easier way.
Note that they auto re-auth whenever they connect/reconnect, and an external source handles the initial authentication.
Beta Was this translation helpful? Give feedback.
All reactions