Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

169
Views
WebSocket connection failed:

I am dealing with an error that says the web socket connection failed in my MERN web app. here is my server site code:

    const http = require('http')
    const { Server } = require("socket.io");
    const app = express();
    app.use(cors());

    let server = http.createServer(app)

    const io = new Server(server, {
      cors: {
        origin: `${process.env.MYBIYESADI}`
      },
      allowEIO3: true
    })
    io.on("connection", function (socket) {
    console.log("a user connected.")
   socket.on("disconnect", () => {
        console.log("a user disconnected!")
        io.emit("onlineUsers", users)
    })
  })

and frontend site code is:

import { io } from "socket.io-client";
const socket = useRef()
useEffect(() => {
    socket.current = io(`${process.env.REACT_APP_API_URL}`, { transports: ["websocket"] })
  }, [])

What's not written as expected? Its working fine locally and I have hosted both in wss and https as in URL but after hosting to aws docker it shows that wss connection failed as

2.647cd368.chunk.js:2 WebSocket connection to 'wss://url/socket.io/?EIO=4&transport=websocket' failed:

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.