Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!