0

I can't connect to the server with socket.io-client

here is how I import socket.io-client import io from "socket.io-client

here I try to connect to io: const socket = io("http://localhost:3000")

then I tried to console log some stuff

useEffect(() => {
        console.log("socket connection established: ", socket.connected)
        const messageInfoLoader = (messageData) => {
          //this messageData is not even logging
          console.log(messageData)
          console.log(messageData.text)
        }

        socket.on("messageInfo", messageInfoLoader)

        socket.on("connect_error", (error) => {
          console.error(error)
        })
  
        return () => {
          socket.off("messageInfo", messageInfoLoader)
          socket.off("connect_error")
        }
      }, [socket])

and I also got bunch of those errors: polling.js:298 GET http://ws/socket.io/?EIO=4&transport=polling&t=OfKIqgW net::ERR_NAME_NOT_RESOLVED

If you know how to fix those please let me know in the comments

when I console log("socket connection established: ", socket.connected), it logs: socket connection established: false

I tried to add connection rule of that port and still it says socket connection established: false

  • update: I changed import like this: `import { io } from "socket.io-client"` and it worked well and there is no more errors, but `socket connection established: false` still occures – George Bazerashvili Sep 02 '23 at 05:28

0 Answers0