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

204
Vistas
Socket.io node server can't emit events to an electron app

I just followed the Get Started tutorial from https://socket.io/get-started/chat. It works with a web client on the browser. But it won't emit any event to a electron client. No error messages in any console. It just won't connect the socket in an electron app to the socket.io server.

The problem seems to be the io.emit() method, commenting that line makes possible for the electron client to successfully connect to the socket.io server.

This is the code of the nodejs server:

const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require('socket.io');
const io = new Server(server);

app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html');
});

io.on('connection', (socket) => {

    console.log('a user connected');

    socket.on('chat message', (msg) => {
        //io.emit('chat message', msg);
        console.log(msg);
    });
    
});

server.listen(3000, () => {
    console.log('listening on *:3000');
});

This is the code of the preload.js of the electron app:

const io = require("socket.io-client");
const socket = io('http://localhost:3000');

socket.on('connect', () => {
    console.log('you are connected!');
});

window.addEventListener('DOMContentLoaded', () => {
    var messages = document.querySelector('#messages');
    var form = document.querySelector('#form');
    var input = document.querySelector('#input');

    form.addEventListener('submit', function (e) {
        e.preventDefault();
        if (input.value) {
            socket.emit('chat message', input.value);
            input.value = '';
        }
    });
})

about 4 years ago · Juan Pablo Isaza
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