Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

486
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda