Tuesday 30 May 2017

how to get socket.id of a connection on client side?

Im using the following code in index.js

io.on('connection', function(socket){
console.log('a user connected');
console.log(socket.id);
});

the above code lets me print the socket.id in console.

But when i try to print the socket.id on client side using the following code

<script>
var socket = io();
var id = socket.io.engine.id;
document.write(id);
</script>

it gives 'null' as output in the browser.



via Black Heart

No comments:

Post a Comment