Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node.js socket.io send data with handshake

/* Client Side: */
//The query member of the options object is passed to the server on connection and parsed as a CGI style Querystring.
var socket = io("http://127.0.0.1:3000/", { query: "foo=bar" });


/*Server Side: */
io.use(function(socket, next){
    console.log("Query: ", socket.handshake.query);
    // return the result of next() to accept the connection.
    if (socket.handshake.query.foo == "bar") {
        return next();
    }
    // call next() with an Error if you need to reject the connection.
    next(new Error('Authentication error'));
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue check if list is empty 
Javascript :: or in js 
Javascript :: vuejs watch sub property 
Javascript :: rectbutton disable 
Javascript :: javascript add quote comma 
Javascript :: javascript recorrer json 
Javascript :: React Native - navigation is undefined 
Javascript :: loop json jquery 
Javascript :: google script get date without time 
Javascript :: character to ascii in js 
Javascript :: js make obj invisible 
Javascript :: javascript random alphabet 
Javascript :: javascript push in specific index 
Javascript :: geolocation async js 
Javascript :: chart js laravel mix 
Javascript :: jquery selector all elements except one 
Javascript :: javascript filter strings for partial matches 
Javascript :: how to get utc time in angular 
Javascript :: angular MatDialogRef spec 
Javascript :: how to play music in js 
Javascript :: javascript get line number of error 
Javascript :: phone number validation regex javascript 
Javascript :: useHistory goback 
Javascript :: change swiper-slide width angular 
Javascript :: body on click function 
Javascript :: react proptypes reuse shape 
Javascript :: javascript excel column letter to number 
Javascript :: protractor right click on element 
Javascript :: prompt node 
Javascript :: como saber si un checkbox esta seleccionado en jquery 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =