10

NodeJS でアプリを作成し、ws モジュールを使用しています。localhost でアプリをテストすると動作し、websocket の接続に問題はありません。これで、アプリを Openshift にアップロードしました。クライアントからアクセスしようとすると、websocket への接続を確立できないというメッセージが返されます。

アプリにパテでテールを作成すると、次のメッセージが表示されます: DEBUG: このタイプの応答には本文を含めてはなりません。end() に渡されたデータを無視します。

サーバーにあるコードは次のとおりです。

#!/bin/env node

//Openshift variables
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "192.168.69.42";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;


//NodeJS require modules
var Enum = require('enum');
var WebSocketServer = require('ws').Server
    wss = new WebSocketServer({host:ipaddress, port:port});
var fs = require('fs');


wss.on('connection', function(ws) {
    console.log((new Date()) + ' Connection from origin: ' + ws._socket.remoteAddress);
});

console.log((new Date()) + " Server is listening on: " + ipaddress + ':' port);

そしてクライアントで:

var ws = new WebSocket("ws://192.168.69.42:8080/");

ws.onopen = function() {
    console.log("Connected.");
    ws.send("This is the client speaking.");
};
4

2 に答える 2