Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

490
Vistas
socket shows connection true and false at the same time, what can cause this issue?

I am trying to create a chat, here is I have created instance of socket and unmounted it, but the issue is the connection shows false and true at the same time, The chats and messages are listened but cannot get the new messages.What is the correct way of using socket.io-client ? help!!

when I console.log(socket) on the client, this prints as follows :

Socket {connected: false, receiveBuffer: Array(0), sendBuffer: Array(0), ids: 0, acks: {…}, …}
acks: {0: ƒ}
connected: true
flags: {}
id: "_klZ4PeyF0r37wPcAABa"
ids: 1
io: Manager {nsps: {…}, subs: Array(5), opts: {…}, setTimeoutFn: ƒ, clearTimeoutFn: ƒ, …}
nsp: "/"
receiveBuffer: []
sendBuffer: []
subs: (4) [ƒ, ƒ, ƒ, ƒ]
_callbacks: {$chats: Array(1), $new_message: Array(1), $message_list: Array(1)}
active: (...)
disconnected: (...)
volatile: (...)
[[Prototype]]: Emitter

when I consolelog(socket.connected),it also returns false, I have created the instance like this,

 useEffect(() => {
    socket = io(`https://samsara-chat.herokuapp.com/?token=${token}`, {
      transports: ['websocket']
      // autoConnect: true
    })
    socket?.connect()
    socket?.emit('chat-list', {})
    socket?.on('chats', (args) => {
      setChats(args.chats)
    })
    socket?.emit('list', { room_id: currentroom })
    socket?.on('message_list', (args) => {
      setMessage((list) => [...args.messages])
    })

    return () => {
      socket?.disconnect()
    }
  }, [socket, currentroom])
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda