Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
socket.io - Failed to load resource: net::ERR_CONNECTION_REFUSED

I'm building a forum where two users after connections can post a status then comment on them. For comments, i used socket.io .

In console i'm getting this error each few seconds :

Failed to load resource: net::ERR_CONNECTION_REFUSED
GET http://localhost/socket.io/?EIO=4&transport=polling&t=O05nump net::ERR_CONNECTION_REFUSED

How to fix this error ?


I installed express, nodemon and socket.io in my socket server:

  • Socket server:

package.json

{
"name": "socket",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
  "express": "^4.17.3",
  "nodemon": "^2.0.15",
  "socket.io": "^4.4.1"
  }
}

app.js

const io = require("socket.io")(4000, {
cors: {
    origin: "http//localhost:3000",
},
});


io.on('connection', (socket) => {
  console.log('A new user is connected !');
})
io.on('disconnect', () => {
  console.log('User has left !');
});

  • Front:

Also, i installed socket.io-client in client (front), then in my web page, i added this code :

import { io } from 'socket.io-client'
export default () => {

  //implement socket
  const socket = useRef()

  useEffect(() => {
      socket.current = io("ws://localhost/4000")
  }, [])

return (
  //some html code
)
}

  • My project tree:

Project Forum

├── back     
├── client
   └──index.jsx
└── socket
   └──package.json
   └──app.js

  • Console Visual Studio Code: Visual studio code's console shows this only how many times i refresh browser or ctrl+S the code:

    [nodemon] starting 'node apde app.js'
    
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You added a slash instead of semi-colon:
socket.current = io("ws://localhost:4000")

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda