Node.js socket app on openshift - node.js

I'm trying to deploy a simple node.js socket app on OpenShift.
First I tried setting up the listener as:
var server = net.createServer(newSocket); //newSocket is a listener method
var port = 8888;
server.listen(port);
and this causes:
Error: listen EACCES
Then I researched a bit and learned that you need to listen using OPENSHIFT_NODEJS properties and set the listener like this:
var server = net.createServer(newSocket);
var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8888;
server.listen(port, ipaddr);
Now the app is started at: 127.6.253.1:8080 - however when I try to telnet it using my OpenShift app url and 8080 I get server timeout.
If you have experience with the similar situation let me know.
The code of the app I'm trying to make it work on OpenShift is at https://github.com/denimf/NodeChat

The internal port for the OpenShift app is 8080, but it is exposed externally on port 80 at the URL specified in your control panel. You can also see the app URL in the console by doing:
echo $OPENSHIFT_APP_DNS

Most of the node.js web hosting services don't support socket listener. I solved my problem by hosting the Node app on a dedicated virtual machine.

Related

Openshift - port to use on deployment

I have the following start.js file:
var express = require('express');
var app = express();
app.use(express.static('static'));
var server = app.listen(8080, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
In my NodeJs application on Openshift. However, when I run rhc tail-a app-name
I can see that there is an error of :
Error: listen EADDRINUSE :::8080
I've tried 80 and 443, and received those errors:
Error: listen EACCESS 0.0.0.0:443
Or 80
Which port should I use as default on my app?
Thanks!
Use Nginx,
Nginx (pronounced "engine x") is a web server. It can act as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache.
It isn't good practice to run your application with root privileges or directly run your application on port 80 and your port 8080 is in use. Try different port and use reverse proxy.
But if you want to run on port 80 or 443, run your application with root privileges.

Running multiple node express applications on single port

I am want to make proxy manger application for express,
but I have error all time that I try to do require for two diffrent applications.
i am using on app.use to route between the two application.
thanks alot
david
var app1 = require('./../app1/server/server');
var app2 = require('./../app2/server/server');
var app = require('express')();
app.use("/", app1);
app.use("/app2", app2);
app.listen(80, console.log("server up"))
Error is :
event,js:85 listen eaddrinuse
The port 80 is in use by another process. try with another empty port like 8080 or 3000. You can also try by stopping the application that is using port 80, then it will work.

nodejs websocket server ip localhost --> openshift

I am trying to migrate my nodejs websocket server from localhost to OpenShift. I managed to get the server running in openshift, but now I am having problems trying to connect to it from my Unity 3D client.
Server code:
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
console.log(server_port);
console.log(server_ip_address);
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ host: server_ip_address, port: server_port });
The server outputs an ip 127.13.159.1 and a port 8080, but when I try to connect from Unity client using this ip and port it says "Error: The WebSocket connection has already been closed."
I am using this package in Unity for websockets https://www.assetstore.unity3d.com/en/#!/content/38367
new WebSocket(new Uri("ws://127.13.159.1:8080"));
To connect to your application using websockets you need to use your ws://app-domain.rhcloud.com:8000 or wss://app-domain.rhcloud.com:8443 (for secure websockets)

Node.js chat server running on "cloud9-ide" is listening but not able to connect using client

Chat server is listening to the port, below snippet is from console log.
Your code is running at https://mynodetest-someone.c9.io.
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!
debugger listening on port 15454
info - socket.io started
Chat server listening at 0.0.0.0:4000
When trying to connect through browser: eg: "localhost:4000", connection is refused(Error code: ERR_CONNECTION_REFUSED)
Can some one help how to fix this issue?.
Note:
I have tried listening on "127.0.0.1" and given original IP address in the network.
You can access the server using the URL that cloud9 provides for that specific server/project.
Use process.env.PORT as the port and process.env.IP as the host for you application and access your app using your project name - username. Should be something like https://mynodetest-someone.c9.io.
From the c9 page:
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!

How get second port from Heroku for websocket

I'm using Heroku to deploy my nodejs game.
Everything works fine but the websockets on my game won't work when I deploy it to Heroku.
Heroku gives me 1 available port (in the var port).
Is there a way to get a second port where my socket can listen to?
If I try to set the socket to the same port as the app.listen, it tells me the port is already in use.
var port = process.env.PORT || 8080;
app.listen(port);
socket = io.listen(8000);

Resources