Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

484
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!