Is this normal behavior? socket.io-1.3.2.js From the client:
socket = io.connect('https://socket.myserver.nl');
socket.on('connect', function() {
socket.emit('register', userID, 'Lobby');//ignore this
});
At the server Node version v5.2.0:
io.sockets.on('connection', function (socket) {
console.log('SOCKET CONNECTING '+socket.id);
////lots of other code//////////
socket.on('disconnect', function() {
console.log('SOCKET DISCONNECTING '+socket.id);
});
});
During test when i make a single connection with a client to the server and further doing absolutely nothing i get the following (5 minutes approximately):
SOCKET CONNECTING SddHIXmWSeHEfDnlAAAC
SOCKET DISCONNECTING SddHIXmWSeHEfDnlAAAC
SOCKET CONNECTING o0zj7GE1tlO3RQw1AAAD
SOCKET DISCONNECTING o0zj7GE1tlO3RQw1AAAD
SOCKET CONNECTING lAnfvaF3DXMyhc6lAAAE
SOCKET DISCONNECTING lAnfvaF3DXMyhc6lAAAE
SOCKET CONNECTING tP3cjtJ-VpPPjoG2AAAF
SOCKET DISCONNECTING tP3cjtJ-VpPPjoG2AAAF
SOCKET CONNECTING a2o13T7CgcKDEbppAAAG
SOCKET DISCONNECTING a2o13T7CgcKDEbppAAAG
SOCKET CONNECTING avogGTh0KVtLFOqNAAAH
SOCKET DISCONNECTING avogGTh0KVtLFOqNAAAH
SOCKET CONNECTING usoQGxKAMsth2zTcAAAI
SOCKET DISCONNECTING usoQGxKAMsth2zTcAAAI
question continues here: socket-io-changes-socket-id-repeatedly part 2
If you use React, Vue or something like that
Create another js file inside src and type these lines for connecting myCustomSocket.Export socket.id and socket. Because you need to run socket.io out of dynamic rendered components.
import { io } from 'socket.io-client';
export const socket = io('http://localhost:5000');
export let socketID = '';
socket.on('connect', () => {
socketID = socket.id
})
And inside React components you can import them.
import { socketID, socket } from './myCustomSocket';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With