I
I
IDONTSUDO2019-12-06 17:58:44
Node.js
IDONTSUDO, 2019-12-06 17:58:44

socket.io reopens connection every 50 seconds what's the problem?

Socket.io-client seems to stop transmitting data. Is there an internal reason for this?
Every 50 seconds, it reopens the connection.
I have a simple Node js socket.io server. And a React client. They work on different ports. Could this be the problem?
Function code, it opens once in componentDidMount()

import io from "socket.io-client";
import { isAuthenticated} from "../Api/Auth"


const jwt = isAuthenticated().token

export const testSoket = () => {
    const socket = io.connect('http://localhost:4001', { query: {
        token: jwt
      }
});
    socket.on("news")
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IDONTSUDO, 2019-12-06
@IDONTSUDO

did it like this. And it does not reconnect, surprisingly. I don't know why, but it works as it should.

import io from "socket.io-client";
import { isAuthenticated} from "../Api/Auth"


const jwt = isAuthenticated().token

const socket = io.connect('http://localhost:4001', 
  { query: {token: jwt} 
})


export const testSoket = () => {
    socket.on("news")
    socket.on('disconnect', function(){});
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question