All I want to do is deploy my little nodeJS app onto the free hosting site, appFog.
Nomatter what ports I set on my client side or on my server side.. I consistently get the error message:
events.js:71
throw arguments[1]; // Unhandled 'error' event
^ Error: listen EADDRINUSE
When this is on my laptop / desktop running on localhost, everything works just fine.
So this is what I've got going on:
Client side:
this.connection = new WebSocket('ws://super1onate.aws.af.cm:1337');
Server Side:
var express = require("express"); // load the express module
var app = express(); // App now holds the server object
// What ports to listen on
app.listen(process.env.VCAP_APP_PORT ||1337);
server.listen(process.env.VCAP_APP_PORT || 1337, function() {
console.log((new Date()) + " Server is listening on port " + webSocketsServerPort); });
Your server code looks ok. What is events.js? It looks like maybe you're including a module that's trying to bind to a port it shouldn't.
Once you get your server running, I don't think your client code will work. As far as I can tell, AppFog doesn't support websockets, and if it does, you'll probably want to hit port 80, not 1337.
Alright, I'm going to answer my own questions.
AppFog does not support WebSockets. websockets =/= socket.io btw fyi
Anyways, according to this site:
http://feedback.appfog.com/forums/171983-appfog/suggestions/3543100-add-websocket-support-to-node-js
Related
I installed Nginx and Node.js in my server.
When I try run my node.js file, I get an error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:614:11)
at Array.0 (net.js:689:28)
at EventEmitter._tickCallback (node.js:192:40)
How can I fix this problem?
Thanks!
I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.
I had my HOST environmental variable pointing to a static IP, and my Node server was listening to that address. At some point when my router recycled, it started assigning my machine a new IP, and I started getting the error you posted. It was fixed by changing the address my server was listening to.
My config:
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
http.createServer(app).listen(app.get('port'), app.get('host'), function(){
console.log("Express server listening on port " + app.get('port'));
});
Make sure your host is hitting your machine. In any case, the loopback, as #miltonb suggested, should always work:
app.set('host', '127.0.0.1');
I think you need a bit more context like some of your code. I am guessing you are starting to listen on a web server or a socket? Based on that assumption, I get something similar when I run a basic web server on my test server unless I run using localhost.
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:670:11)
at Array.0 (net.js:756:28)
at EventEmitter._tickCallback (node.js:190:38)
Try changing the [hostname] parameter to localhost:
var http = require('http');
http.createServer( function ).listen(8000, '127.0.0.1');
I was getting the same error, and then I changed the port and worked
Could it be that node was already running a server? I received a similar error and found this while troubleshooting. Shutting down the previous node server solved my problem.
For me, the issue was that the IP that I wrote simply didn't exists :) usually at home I have a 192.168.x.x IP, and after a restart I had a different address ... when I tried to gulp serve my app - it had a config with the old IP ....
as always 127.0.0.1 will work, but when you want to verify your website with other devices, you want to use the external IP 192.168.x.x ... or similar.
Most of the time it would be the IP address or the hostname. The reason being, node js takes that as the key item to start the server. if there is a conflict or incorrect ip address, it cribs with this error
Error: listen EADDRNOTAVAIL
hope this helps.
For me , i had the same error , and when i check my configuration , i found that host=127.0.0.0 which raises error because it should be 127.0.0.1 instead of 127.0.0.0
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');
app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('host') + ':' + app.get('port'));
});
works for me.
it also generic for debug by localhost and your local ip without any changes.
This also will occur while 'ip addr add i:p:v:6' is still in limbo or something (just executed/ing), and the interface is I presume not totally ready to listen and still busy adding the new ipv6 address.
Using an execSync [see https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options] to call 'sleep' for a 2 second pause seems to allow listen to not error with Error: listen EADDRNOTAVAIL.
[It's really a bug I think in NodeJS 7.4.0 on Ubuntu because this doesn't happen with ipv4 address creation at the instant before usage/listen connection.]
Check your ip ipconfig adress and add any port 3004 for example.
Code below finally work for me. In case if you want to access this server from other device in your network. Or just set local host ip to 127.0.0.1 and get access from your device.
var server = require('http').createServer(app);
server.listen(3004, '192.168.x.x', function () {
console.log("Listening on port 3000!");
});
In my case, I fixed it by checking the directory /tasks/options
I found connect.js file which had static IP address which was incorrect. I just changed it to the correct one and it worked.
I need to build a socket.io server that will intercept incoming connections from an app which is not stored in the same directory as the server.
The client side app does not contain node.js, thus I'm trying to use a websocket :
Telnet.Socket = new WebSocket('ws://127.0.0.1:3000');
My node.js server does not need a http server but must be a standalone socket.io app. Thus, I've tried the following code :
var io = require('socket.io')();
io.on('connection', function(socket){
console.log('connexion entrante');
});
io.listen(3000);
Unfortunately, the server part does not seem to get the Websocket connection request. My firefox says :
Firefox cannot establish a connection with the server at adress ws://127.0.0.1:3000/.
What am I missing ?
Thx in advance !
socket.io need client use socket.io to connect because it use many kind of connection. For connect websocket only you can use ws node module
I have spent literally all day visiting tutorial websites explaining how to use nodejs and sockoets.io but I'm not able to get anything to work.
I have managed to at least run a js file:
node filename.js
But it doesnt fully work. It runs until it reaches the "var server = net..." line since the "console.log("hello")" line DOES NOT EXECUTE:
var net = require('net');
var server = net.createServer(function (socket) {
console.log("hello");
socket.write('Echo server\r\n');
socket.pipe(socket);
});
console.log("hello");
server.listen(1337, '127.0.0.1');
This i got from the official node.js site home page:
http://nodejs.org/
All tutorials claim that its just so easy.
I have just tried to follow this tutorial to the letter although a lot of them skim over the part I'm stuck with (the actual installing):
http://tutorialzine.com/2012/08/nodejs-drawing-game/
so following the above tutorial i run app.js from the console and i get a message "socket.io started", I get stuck at the part where it asks for you to go to this URL:
http://localhost:8080
The browser attempts to go there but it hangs for a few minutes then says:
"No data received
Unable to load the webpage because the server sent no data."
I have no idea how node.js works and there don't seem to be explanations as to how it works...
Where is node.js installed? If its meant to be on the server, how does it get installed on the server? where should I install it to test locally? what is socket.io? where should that be installed?
All I seem to get on node.js info sites are code block dumps with little explanation as what is going on.
I followed a youtube tutorial where the guy was using WAMP server, so I thought maybe I needed to put files on a server, so I installed WAMP and disabled IIS8 server. Another note, when going to "localhost" on my browser it says "it works!" which seems like an automating message from a local server - I thought it was IIS8 but even though I disable the service, that message displays. Even if I install WAMP and have it running that message displays. Also, WAMP doesn't work either, since php files don't run. Localhost always takes me to a page displaying that message.
Is this a local server issue?
it is hard to give an "answer" to your question(s). I would recommend you start with a much more basic introduciton that the drawing game. Also, I would suggest you start with nodejs as is, without using socket.io right away. when you understand how node works, you can start with websockets.
Here is some node 101 stuff:
http://www.nodebeginner.org/
http://thatextramile.be/blog/2011/12/node-js-for-dummies/
You should not need WAMP at all. nodjs is the server!
It seems that you have no idea what ports are. Your node script start a webserver that listens on port 1337. If you want to see what that server serves, you need to point your browser to localhost:1337 (not port 8080, as you tried)
I have created a basic gist on github for using socket.io + node + express
The minimum working environment for making socket.io app is this :
var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app),
io = require('socket.io').listen(server);
app.get('/', function(req, res) {
res.send('<!doctype html> \
<html> \
<head><meta charset="utf-8"></head> \
<body> \
<center>Welcome to <strong>socket.io</strong></center> \
<script src="/socket.io/socket.io.js"></script> \
<script> \
var socket = io.connect(); \
socket.emit("message", "Howdy"); \
setInterval(function () { \
socket.emit("message", "Ping"); \
}, 1000); \
</script> \
</body> \
</html>');
});
io.sockets.on('connection', function (socket) {
socket.on('message', function(msg) {
console.log(msg);
});
});
server.listen(8000);
you need to require('socket.io') and then create a connection io.sockets.on('connection', function (socket) in order to make it work
I installed Nginx and Node.js in my server.
When I try run my node.js file, I get an error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:614:11)
at Array.0 (net.js:689:28)
at EventEmitter._tickCallback (node.js:192:40)
How can I fix this problem?
Thanks!
I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.
I had my HOST environmental variable pointing to a static IP, and my Node server was listening to that address. At some point when my router recycled, it started assigning my machine a new IP, and I started getting the error you posted. It was fixed by changing the address my server was listening to.
My config:
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
http.createServer(app).listen(app.get('port'), app.get('host'), function(){
console.log("Express server listening on port " + app.get('port'));
});
Make sure your host is hitting your machine. In any case, the loopback, as #miltonb suggested, should always work:
app.set('host', '127.0.0.1');
I think you need a bit more context like some of your code. I am guessing you are starting to listen on a web server or a socket? Based on that assumption, I get something similar when I run a basic web server on my test server unless I run using localhost.
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:670:11)
at Array.0 (net.js:756:28)
at EventEmitter._tickCallback (node.js:190:38)
Try changing the [hostname] parameter to localhost:
var http = require('http');
http.createServer( function ).listen(8000, '127.0.0.1');
I was getting the same error, and then I changed the port and worked
Could it be that node was already running a server? I received a similar error and found this while troubleshooting. Shutting down the previous node server solved my problem.
For me, the issue was that the IP that I wrote simply didn't exists :) usually at home I have a 192.168.x.x IP, and after a restart I had a different address ... when I tried to gulp serve my app - it had a config with the old IP ....
as always 127.0.0.1 will work, but when you want to verify your website with other devices, you want to use the external IP 192.168.x.x ... or similar.
Most of the time it would be the IP address or the hostname. The reason being, node js takes that as the key item to start the server. if there is a conflict or incorrect ip address, it cribs with this error
Error: listen EADDRNOTAVAIL
hope this helps.
For me , i had the same error , and when i check my configuration , i found that host=127.0.0.0 which raises error because it should be 127.0.0.1 instead of 127.0.0.0
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');
app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('host') + ':' + app.get('port'));
});
works for me.
it also generic for debug by localhost and your local ip without any changes.
This also will occur while 'ip addr add i:p:v:6' is still in limbo or something (just executed/ing), and the interface is I presume not totally ready to listen and still busy adding the new ipv6 address.
Using an execSync [see https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options] to call 'sleep' for a 2 second pause seems to allow listen to not error with Error: listen EADDRNOTAVAIL.
[It's really a bug I think in NodeJS 7.4.0 on Ubuntu because this doesn't happen with ipv4 address creation at the instant before usage/listen connection.]
Check your ip ipconfig adress and add any port 3004 for example.
Code below finally work for me. In case if you want to access this server from other device in your network. Or just set local host ip to 127.0.0.1 and get access from your device.
var server = require('http').createServer(app);
server.listen(3004, '192.168.x.x', function () {
console.log("Listening on port 3000!");
});
In my case, I fixed it by checking the directory /tasks/options
I found connect.js file which had static IP address which was incorrect. I just changed it to the correct one and it worked.
Is there a good way of using sessions with Socket.io in Express 3.0? A way of getting the clients' session id in a safe way? So that I can send notices to members specific to their account and make private chats from member to member?
I'm using MySQL store in Express 3.0
I wrote a tiny module to abstract it, here's how its usage looks like. It was written and tested using express 3, socket.io 0.9.10 and the (default) MemoryStore from connect 2.4.5. It should work fine with other compatible stores.
var SessionSockets = require('session.socket.io')
, sessionSockets = new SessionSockets(io, sessionStore, cookieParser);
sessionSockets.on('connection', function (err, socket, session) {
//your regular socket.io code goes here
});
For more details on how it works see https://github.com/wcamarao/session.socket.io
You might want to pay attention to the part of the README where it says how to use it with your own session store key (I'm assuming your mysql store uses a name other than the default 'connect.sid').
You should check out express.io, a very simple micro-framework for express and socket.io integration. It handles express and socket.io sessions automatically.
npm install express.io
Check out the session support example here:
https://github.com/techpines/express.io/tree/master/examples#sessions
I did something slightly different to get it working. I read through a lot of posts on nodester github and came with the following solution....
Replace:
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
with:
var server = http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
var io = require('socket.io').listen(server);
My plan is to continue with this workaround until issues around express3 and socket.io are resolved.