http://stackoverflow.com/questions/37576748/socket-io-client-and-server-socket-id-different
I am having trouble with socket server and client socket.id. With node@5.6.0 and socket@1.4.6 I am getting different socket.id from client (socket.io-client) and server (socket) not sure if this is expected in the latest version? e.i the difference is that the server side socket.id has /#IAPEFvUDQkfV0NxcAAAA and client side socket.id has IAPEFvUDQkfV0NxcAAAA where as if I use the socket@1.3.1 I get the same socket.id from client and server.
This is the version...
admin$ npm list | grep socket
├─┬ socket.io@1.4.6
│ ├─┬ socket.io-adapter@0.4.0
│ │ └─┬ socket.io-parser@2.2.2
│ ├─┬ socket.io-client@1.4.6
│ └─┬ socket.io-parser@2.2.6
├─┬ socket.io-client@1.3.1
│ ├─┬ socket.io-parser@2.2.2
├─┬ socket.io-stream@0.6.1
admin$ npm --version
3.6.0
admin$ node --version
v5.6.0
admin$
This is the server test_socket_server code
# test_socket_server.js
var io = require('socket.io').listen(5000);
var serverurl = "http://0.0.0.0:5000/";
io.sockets.on('connection', function (socket) {
var socketid = socket.id
console.log('serversocketid', socketid)
socket.on('get_socketid_from_client', function(clientsocketid) {
console.log('get_socketid_from_client-clientsocketid', clientsocketid)
io.to(clientsocketid).emit('test_emit_on_clientsocketid')
io.to('/#'+clientsocketid).emit('test_emit_on_clientsocketid_modified')
socket.emit('test_emit_on_serversocketid')
})
});
This is the client test_socket_client code
# test_socket_client.js
var io_client = require('socket.io/node_modules/socket.io-client')
var serverurl = "http://0.0.0.0:5000/";
var options = {
transports: ['websocket'],
'force new connection': true
};
var socket = io_client.connect(serverurl, options);
socket.on("connect", function () {
console.log('clientsocketid', socket.id);
socket.emit('get_socketid_from_client', socket.id, function(data) {
console.log('get_socketid_from_client', data)
});
});
socket.on("test_emit_on_clientsocketid", function () {
console.log('test_emit_on_clientsocketid successful')
});
socket.on("test_emit_on_clientsocketid_modified", function () {
console.log('test_emit_on_clientsocketid_modified successful')
});
socket.on("test_emit_on_serversocketid", function () {
console.log('test_emit_on_serversocketid successful')
});
These are the result...
# Server side
$ node test_socket_server.js
serversocketid /#IAPEFvUDQkfV0NxcAAAA
get_socketid_from_client-clientsocketid IAPEFvUDQkfV0NxcAAAA
$
# Client side
$ node test_socket_client.js
clientsocketid IAPEFvUDQkfV0NxcAAAA
test_emit_on_clientsocketid_modified successful
test_emit_on_serversocketid successful
$
http://stackoverflow.com/questions/37576748/socket-io-client-and-server-socket-id-different
I am having trouble with socket server and client socket.id. With
node@5.6.0andsocket@1.4.6I am getting differentsocket.idfrom client (socket.io-client) and server (socket) not sure if this is expected in the latest version? e.i the difference is that the server sidesocket.idhas/#IAPEFvUDQkfV0NxcAAAAand client sidesocket.idhasIAPEFvUDQkfV0NxcAAAAwhere as if I use thesocket@1.3.1I get the same socket.id from client and server.This is the version...
This is the server
test_socket_servercodeThis is the client
test_socket_clientcodeThese are the result...