electron: timeout issue in node modules

I’m trying to use socket.io-client from electron v0.27.1, but connecting to the server does not work like expected.

main.js - my electron app client.js - client without electron, this works server.js

  1. running main.js with electron path/to/my/app while server.js is running, I get timeouts
  2. if I put the call to initSocket() in main.js before app.on(ready", ...) it successfully connects but I have to wait like 25 seconds before it happens
  3. running client.js with io.js v1.6.3 works like a charm (even with the same socket.io options as in main.js)

Any idea what’s happening?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 2
  • Comments: 20 (5 by maintainers)

Most upvoted comments

What does closed due to abandonment mean? Abandoned by whom? I think a lot of people would still consider this an issue…

I’ve finally done it, it seems like a problem with XHR / JSONP polling transport. I am using electron 1.0.2 and socket.io 1.4.6

Just specify in your client when setting the connection that you only want to use websockets.

var socket = require('socket.io-client')('http://localhost:5000', { transports: [ "websocket" ] });

Hope this helps

I am also affected by this (Ubuntu 15.10, electron-prebuilt 1.2.8, socket.io-client 1.4.8). I had the same experience as @andresmeidla, forcing websocket transport didn’t fix it in the end. Thanks to @darky! Switching from “localhost” to the ip seems to work for now, at least for testing locally.

Forcing it to use websockets as transport doesn’t seem to be a solution (at least for me). I tried it a couple of days ago, and it seemed to work fine at first - client connected right away, messages got delivered etc. But the error returned after some time (couple of hours and lots of connecting/disconnecting, appliance restarts). So my guess is that all it did is change some internal timing so that it happened to succeed at first.