最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - OpenShift NodeJS deployment : socket.io index.html port assignment, etc - Stack Overflow

matteradmin12PV0评论

I locally wrote a nodeJS app using socket.io and express modules. I wanted to use openshift for hosting. So I changed the main .js to server.js which seems to be the index equivalent of the openshift file and changed the server port setting to:

var server = require('http').createServer(app).listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);

as indicated in some posts. However after git mit, I am still getting:

remote: info: socket.io started remote: warn: error raised: Error: listen EACCES remote: DEBUG: Program node server.js exited with code 0 remote: remote: DEBUG: Starting child process with 'node server.js'

and the website doesn't work.

As the app is serving a html file, there are two more places, where the port is mentioned, which sit in the index.html that is served:

header:

<script src='//localhost:3000/socket.io/socket.io.js'></script>

and within javascript for the html file:

var socket = io.connect('//localhost:'+process.env.OPENSHIFT_NODEJS_PORT || 3000);

// intial vars and multi list from server socket.on('clientConfig', onClientConfig);

All files and modules are seemingly uploaded, but the EACCES error still prevails.

I get the feeling that maybe the header link to localhost:3000 might be the skipping point, but I am not sure. Anyone have any idea, what the problem is? Also, there is no : socket.io/socket.io.js file in the socket.io modules folder, which I find confusing.

I locally wrote a nodeJS app using socket.io and express modules. I wanted to use openshift for hosting. So I changed the main .js to server.js which seems to be the index equivalent of the openshift file and changed the server port setting to:

var server = require('http').createServer(app).listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);

as indicated in some posts. However after git mit, I am still getting:

remote: info: socket.io started remote: warn: error raised: Error: listen EACCES remote: DEBUG: Program node server.js exited with code 0 remote: remote: DEBUG: Starting child process with 'node server.js'

and the website doesn't work.

As the app is serving a html file, there are two more places, where the port is mentioned, which sit in the index.html that is served:

header:

<script src='//localhost:3000/socket.io/socket.io.js'></script>

and within javascript for the html file:

var socket = io.connect('//localhost:'+process.env.OPENSHIFT_NODEJS_PORT || 3000);

// intial vars and multi list from server socket.on('clientConfig', onClientConfig);

All files and modules are seemingly uploaded, but the EACCES error still prevails.

I get the feeling that maybe the header link to localhost:3000 might be the skipping point, but I am not sure. Anyone have any idea, what the problem is? Also, there is no : socket.io/socket.io.js file in the socket.io modules folder, which I find confusing.

Share Improve this question asked Mar 27, 2014 at 17:42 Marcus KirschMarcus Kirsch 872 silver badges7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

I had recently developed a chat client application using socket.io and also had webrtc in it. I was able to deploy the app on openshift by making the following changes into code.

Client Side

Keep the include script tag in a relative manner like so

<script src="/socket.io/socket.io.js"></script>

While declaring io.connection, change the ip part to point the application to server in this format.

var socket = io.connect('http://yourapp-domain.rhcloud.:8000/', {'forceNew':true });

8000 is for http and 8443 is for https

Server Side

The io and the server should both be listening on the same port and the order in which the statements are run should also be given attention.

Step 1: Declare the http server using app. ( app is obtained from express)

var express = require('express');var app = express();) var server = require('http').Server(app);

Step 2:

Declare io from socket.io and bine it with the server object. var io = require('socket.io').listen(server);

Step 3:

Now, allow the server to listen to openshift port and ip.

server.listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP);

Please pay special attention to the order of the statements you write, it is the order which causes issues.

The server side of your websocket needs to listen on port 8080 on your openshift ip address, the CLIENT side needs to connect to your ws://app-domain.rhcloud.:8000

I have a few notes on how to use WebSockets here: https://www.openshift./blogs/10-reasons-openshift-is-the-best-place-to-host-your-nodejs-app#websockets

You don't need any additional server-side changes after adapting your code to take advantage of environment variables (when available)

OpenShift's routing layer exposes your application on several externally-accessible ports: 80, 443, 8000, 8443.

Ports 8000 and 8443 are both capable of handling websocket connection upgrades. We're hoping to add support for WebSocket connections over ports 80 and 443 soon.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far