can we pass a parameter to io.on(); which could be used as socket.id during connection instead of the automatic generated socket id? if so...can it be done via var socket=io(); ?
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/',function(req,res){
res.sendfile('client.html');
});
io.on('connection',function (socket) {
console.log("connected");
socket.on('disconnect',function(data){
console.log( socket.id+" disconnected");
});
});
http.listen(3000,function(){
console.log("listening on port 3000");
});
what i have been doing till now is to store socket id in session and then overwrite the auto generated socket id with it...its not a good approach though. i dont want to change the socket id to a custom id after the connection has occurred, i want the connection to initialise the socket with that custom id in the first place.
`
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket=io();
</script>
...</html>