OpenShift 上的 WebSockets 不适用于远程客户端 [英] WebSockets on OpenShift do not work with remote client

查看:59
本文介绍了OpenShift 上的 WebSockets 不适用于远程客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无法解决的问题.我使用 socket.io 或 WebSockets 节点 js 库在 openshift 卡盒上实现了一个节点 js WebSockets 服务器.使用它们中的任何一个,结果都是一样的.

I have an issue that I cannot solve. I implemented a node js WebSockets server on an openshift cartridge using socket.io or WebSockets node js libraries. With any of them the result is the same.

在同一个 openshift 平台上运行 node js 客户端,一切正常.

With a node js client running on the same openshift platform everything works ok.

当客户端在我的本地电脑上移动时,客户端连接并突然断开连接,给出 1011 内部服务器错误.

When the client is moved on my local pc the client connects and suddenly disconnects giving a 1011 internal server error.

我尝试在 WebSockets.Org 上使用其他知名客户端,例如回声服务href="http://jsfiddle.net/EAVvQ/516/" rel="nofollow">jsfiddle 但结果是一样的,连接上突然断开.

I tried using other well known clients like the echo service on WebSockets.Org or jsfiddle but the result is the same, connect and suddenly disconnect.

不知道为什么.有人能够从远程连接到 openshift WebSockets 服务器吗?服务器是最小的和简单的,在本地它工作正常.

Do not know why. Have someone been able to connect to an openshift WebSockets server from remote? The server is minimal and simple, and locally it works ok.

这是我用作服务器的代码:

This is the code I am using as the server:

var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port      = 8000;

var app = require("express");
var server = require("http").Server(app);
var io = require("socket.io")(server);

var handleClient = function (socket) {
    // we've got a client connection
    socket.sendUTF("hello");
    console.log("connect");
};

io.on("connection", handleClient);

server.listen(port, ipaddress);

这是套接字端点:ws://js-camillorh.rhcloud.com:8000

And this is the socket endpoint: ws://js-camillorh.rhcloud.com:8000

谢谢!

在评论后将代码更新为:

Updated the code to this after comments:

var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var app = require("express");
var server = require("http").Server(app);
var io = require("socket.io")(server);

var handleClient = function (socket) {
    socket.sendUTF("hello");
    console.log("connect");
};

io.on("connection", handleClient);

console.log("listen: "+ipaddress+" "+port);
server.listen(port, ipaddress);

日志文件是这样的:

DEBUG: Sending SIGTERM to child...
DEBUG: Running node-supervisor with
DEBUG:   program 'server.js'
DEBUG:   --watch '/var/lib/openshift/5551a336e0b8cd4ea50000db/app-root/data/.nodewatch'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'node|js|coffee'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/5551a336e0b8cd4ea50000db/app-root/data/.nodewatch' for changes.
listen: 127.13.35.129 8080

推荐答案

你绑定的端口不对,你需要像这样绑定到8080:

You are binding to the wrong port, you need to bind to 8080 like this:

var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;

然后您仍将使用此网址访问您的应用程序:

Then you will still access your application with this url:

ws://js-camillorh.rhcloud.com:8000

或用于安全的 websockets

or for secure websockets

wss://js-camillorh.rhcloud.com:8443

这篇关于OpenShift 上的 WebSockets 不适用于远程客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆