Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket io changes socket.id repeatedly

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

like image 214
ingridsede Avatar asked Sep 18 '25 15:09

ingridsede


1 Answers

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';
like image 81
Ilkay Citak Avatar answered Sep 21 '25 08:09

Ilkay Citak