Mohsen Shakiba
Mohsen Shakiba

Reputation: 1872

websockets - reject a socket connection

I'm using ws as the socket library for my node.js library.
so my question is, how can I reject a connection if the user doesn't pass the authorization process.

var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 6969});

wss.on('connection', function(socket){
// if the socket.upgradeReq.headers.cookie doesn't exists, reject the client
})

thanks a lot

Upvotes: 4

Views: 8704

Answers (2)

Delcon
Delcon

Reputation: 2555

it is socket.disconnect() for the current version

Upvotes: 4

robertklep
robertklep

Reputation: 203359

You can either use socket.close() or socket.terminate() to close the connection.

Upvotes: 4

Related Questions