Electron as Socket.IO Server?


#1

Is it possible to have Electron act as a Socket.IO server? I have npm install socket.io ran and in my js after app.on('ready', callback); I declare my server

var server = require('http').createServer();
var io = require('socket.io')(server);

io.on('connection', function(socket){
	socket.on('event', function(data){});
	socket.on('disconnect', function(){
		console.log('gone');
	});
});
server.listen(80);

But when I try to connect to the server I get a Socket.EVENT_CONNECT_ERROR event. I am using the com.github.nkzawa:socket.io-client:0.3.0 Java library to connect. link. Am I missing something?


#2

I can’t answer that question, but I am curious:
Will your application serve only as that server? If so, Electron would probably not really be the right platform to use since it is very much geared towards desktop UI apps.


#3

I am going to stick with electron as I have a plan for a desktop UI as well, the server is just a convenience. I did get this working, will investigate my solution and post back later today ideally. Out of curiosity what other software would you use for just a service sort of application?


#4

Yea do let us know what you’re developing there, would be cool to see.

As for a socket-only kind of service, forever is a popular npm package that makes sure your node server stays online and available.
You can even cluster it horizontally with some packages, though I have no experience doing that.


#5

You could also use the Node API within Electron to fork a child process that runs true Node and see if that works (i.e. this API). This adds another layer of complexity since you have to use IPC to talk between the processes but could be a solution to your problem.


#6

No need to add that complexity for my current situation. Right now I am running into a data transfer rate issue with Android Wear. Kind of at a wall. I will have to try implementing the Channel API for Android to see if that fixes my issue but I don’t have high hopes.


#7

wish to know your solution towards electron as socket.io server.
i need the desktop app able to be remote control by mobile app.