I am getting this error:
WebSocket connection to 'ws://localhost:8000/socket.io/?EIO=3&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I have looked for this error but it seems for me that my configuration of the sockets is well and I do not think is for the warning of electron.
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var JSONTCPSOCKET = require('json-tcp-socket');
var JSONTCPSOCKET = new JSONTCPSOCKET({tls: false});
require("./rabbit")(io, JSONTCPSOCKET);
var socket = io('http://localhost:8000',{transports: ['websocket',
'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'polling']});
Any idea?
Thanks mates!!
It was a silly mistake.
The file that contains the server that listen in that port is in my case server.js.
When you run it with node, the start file is server.js but when you run it with electron the start file is main.js and I was never running server.js when I executed with electron, so I was not listening in that port.
Related
In my app.js file, I have the following code
var express = require('express');
var app = express();
var port = 8080;
var util = require('util');
var router = require('./base/js/routes.js');
//==================================================================
app.use('/', router);
// start the server
app.listen(port, function(request, response) {
console.log('Port 8080: Server Begins');
});
//==================================================================
var ipaddress = '123.456.789';
//==================================================================
var mongoose = require('mongoose');
var mongoURI = "mongodb://"+ ipaddress +":27017/test";
var MongoDB = mongoose.connect(mongoURI);
MongoDB.on('error', function(err) {
console.log(err.message);
});
MongoDB.once('open', function() {
console.log("mongodb connection open");
});
//==================================================================
The line var MongoDB = mongoose.connect(mongoURI);
is causing nodeJS not to work. I do not know why. NodeJS is on port 8080 and MongoDB is on port 27017.
I am fairly certain I installed mongodb package (and opened the port correctly). I just do not understand why nodeJS doesnt work when i include that connection line.
Side Note: Also I have the package forever installed: forever start -c nodemon app.js for nodeJS. If that is any relevance.
You are using wrong IP address format.
First try to connect with your local mongoDB instance if it work then you to check the IP address your trying to connect is correct or not.
Add the correct error message if problem still remain same.
change your mongod.conf file from /etc folder
In mongod.conf you need to change bindIp
If connection is local then set bindIp as
bindIp = 127.0.0.1
and if you want to use remote database then change bindIp as
bindIp = 0.0.0.0
then restart mongo service
hope this helps...
I am trying to run a node js app on Heroku using WebSockets. However, I am not able to resolve this error (As seen in conosle of Chrome browser)
WebSocket connection to 'wss://myappname.herokuapp.com:27225/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I am using 'wss' since Heroku runs on HTTPS.
My client side code is :
$.get("https://myappname.herokuapp.com/port",function(data){
port = data;
console.log(data);
host = 'wss://myappname.herokuapp.com:' + port + '/';
ws = new WebSocket(host);
});
My server side code is :
var WebSocketServer = require("ws").Server
var fs = require('fs');
var express = require('express');
var app = express();
var http = require('http');
var port = process.env.PORT || 5000;
var request = require('request');
var server = http.createServer(app);
var serverOnPort = server.listen(port);
console.log("Server listening on port ",port);
var wss = new WebSocketServer({server: serverOnPort});
console.log("websocket server created");
Any help would be appreciated.
Thank You.
So it seems like I was trying to over-do it with the port number. Just using the host as wss://myappname.herokuapp.com/ works well.
I also found this problem. It seems Heroku will automatically route port number. It does's allow to specify port number in url. In my chrome, it show ERR_CONNECTION_RESET. This also happen with XMLHttpRequest. Port number still need when you test with localhost or another server which is not Heroku.
I tried to connect python client to node.js server, and experience HTTP 400 errors.
node.js server code:
var socket = require('socket.io');
var express = require('express')
, http = require('http');
var app = express();
app.set('port', process.env.PORT || 8080);
var server = http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
var io = socket.listen(server);
io.sockets.on('connection', function () {
console.log('hello world im a socket');
});
python client code:
from socketIO_client import SocketIO
def on_response(*args):
print 'on_response', args
import logging;
logging.basicConfig(level=logging.DEBUG)
socketIO = SocketIO('localhost', 8080)
socketIO.on('news', on_response)
socketIO.wait(seconds=1)
when i run client.py after starting the server getting the following error:
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost
DEBUG:requests.packages.urllib3.connectionpool:"GET /socket.io/1/ HTTP/1.1" 400 None
If I create a javascript client, then it works well. Could someone help me resolve this issue please?
I am starting two different node servers, on different ports, but I still get the following error.
info - socket.io started
info - FlashPolicyFileServer received an error event:
listen EADDRINUSE
This is how I am starting the first server:
"use strict";
var
express = require('express'),
app = module.exports = express();
// set some config vars
var
server = require('http').createServer(app),
socket = require('./app/lib/socket');
// these settings are common to both environments
app.configure(function () {
// configuration left out
app.use(app.router);
});
// Load the routing
require('./app/routes')(app);
// run the server with socket.io
server.listen(3001);
socket.listen(server, session, app);
I am starting the second server the exact same way except the second last line is changed to :
server.listen(3002);
socket.io is started like this in another file
exports.listen = function (server, sessionStore, app) {
var io = require('socket.io').listen(server);
...
Not sure how to fix this error.
The flash policy port defaults to 10843, so both apps will try to run it off this port, which is the error you are getting. Either remove the transport, or set the port using
io.set('flash policy port', 3005)
Or you can just remove that transport altogether:
io.set('transports', [
'websocket',
'xhr-polling',
'htmlfile',
'jsonp-polling'
]);
I have the following server.js running:
module.exports = server;
var express = require('express');
var fs = require('fs');
var server = express.createServer();
var port = 58000;
server.listen(port);
var io = require('socket.io').listen(server);
server.use(express.static('/', __dirname + '/../public'));
server.use(express.logger());
io.on('connection', function(client){
console.log('new client connected ' + client);
client.on('message', function(){
console.log('client wants something');
});
});
Simple express.static server for files in a /public subfolder, plus socket.io functionality. With this setup, any request for the 'socket.io.js' file fails, i.e.
http://localhost:58000/socket.io/socket.io.js
returns a 404 error (file not found). Static file server works correctly. If I simply use the 'http' module instead of 'express' (commenting out express.static and express.logger lines) socket.io.js is served correctly. How can I combine both functionalities?
Express 3.0.0 (lastest) change its API.
Here is a question very similar to yours that delivers the response.
var express = require('express')
, http = require('http');
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
...
server.listen(8000);
Make sure you have the last versions of express.js and of socket.io.js.
My side it's working great with
express#2.5.8
socket.io#0.8.5
node#0.6.5
Otherwise, a solution can be to call var io = require('socket.io').listen(server); after your server.use