Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close websocket connection? #32

Open
uLan08 opened this issue Jul 27, 2017 · 3 comments
Open

Close websocket connection? #32

uLan08 opened this issue Jul 27, 2017 · 3 comments

Comments

@uLan08
Copy link

uLan08 commented Jul 27, 2017

How would you properly close a websocket connection? Basically what I am trying to do is check if correct query string parameters are not present then I close the connection.
Here's what I am trying to do right now.

app.ws.use(route.get('/ws',  (ctx) => {
	const { foo, bar } = ctx.query
	if (!foo && !bar) {
		ctx.websocket.close(1000, 'Wrong or missing parameters')
		ctx.websocket.terminate()
                return
	}
}))

I am not really sure if this is correct because I keep on getting socket hang up messages and if I remove the return everything after the if statement still gets executed. I also tried using onclose event on the client but it never triggers.

@ZengTianShengZ
Copy link

I have the same problem 😢

@skomarfaruque
Copy link

i have the same problem? i can only use message. How can i use connected and disconnected?
Thanks in advance.

@rambo-panda
Copy link

wsmodule has a options verifyClient
https://github.com/websockets/ws/blob/master/doc/ws.md#optionsverifyclient

websockets/ws#517

I hope to add a reject function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants