chat-app icon indicating copy to clipboard operation
chat-app copied to clipboard

fix: React doesn't connect to socketIO

Open michalismichailidis1999 opened this issue 3 years ago • 0 comments

Your React Application can't connect to socketIO

Tips to fix this

  • Remove socket.io and socket.io-client because you are using very old versions
  • Install them again

This is how you can connect now

const http = require("http")
const {Server} = require("socket.io");

const app = require("express")();

const server = http.createServer(app)

const io = new Server(server, {cors: {origin: 'http://localhost:3000'}});

io.on("connection", socket => {
  console.log("connected");
})

const port = process.env.PORT || 5000;

server.listen(port, () => console.log(`Listening on port ${port}`))

michalismichailidis1999 avatar Nov 11 '21 06:11 michalismichailidis1999