Details Regarding SERVER and CLIENT.
socket.io on server side (NODEJS)
socket.io-client on client side (also in NODEJS)
Nothing is logged on the SERVER side, as the server never lets the client connect to itself.
Whereas on the CLIENT side I see this output: 'I HAVE CONNECTED.'
SERVER CODE:
var io = require('socket.io')(server);
io.use(function(socket, next){
if (socket.handshake.query.user === "admin") {
console.log("CALLED BEFORE CONNECTION........ :)");
return next();
}
return next(new Error('Authentication error'));
});
io.on('connection', function(socket) {
console.log('CLIENT HAS CONNECTED.');
});
CLIENT CODE:
var io = require('socket.io-client');
var socket = io.connect('http://localhost:5000', { query: "user=admin11" });
socket.on('connect', function (socket) {
console.log('I HAVE CONNECTED.');
});
via CoderX
No comments:
Post a Comment