2016-10-29 4 views
0

私はOpenShift Node.jsアプリケーションを動作させようとしていますが、WS接続は機能しません。クライアントエラー:接続が拒否されました。 クライアント側の工場サービス:Openshift WebSocketに接続する問題

var dataStream = $websocket(localStorageService.get('wsUrl')) 

dataStream.onMessage(function(message) { 
    var call = JSON.parse(message.data) 
    if (fnMap[call.fn]) { 
     fnMap[call.fn](call.event, call.data) 
    } 

}) 

dataStream.onError(function(err) { 
    console.log(err) 
}) 

dataStream.onClose(function(event){ 
    console.log('event: ' + JSON.stringify(event)) 
}) 

var fnMap = { 
    "broadcastResult": function(event, data) { 
     $rootScope.$broadcast(event, data) 
    } 
} 
var methods = { 
    callFn: function(paramJSON) { 
     dataStream.send(JSON.stringify(paramJSON)); 
    } 
} 
return methods 

私は、次のURLに接続しようとしている:WS://myapp-myname.rhcloud.com:8000

あなたが助けてくださいもらえますか?

はチャバ

答えて

0

まず、事前に をありがとう、あなたはws、必ずWebSocketのライブラリーを作製することができます、あなたのpackage.jsonの依存関係のセクションでそれを宣言し、別のgit pushを行うことによってインストールされます。具体的にhttps://blog.openshift.com/paas-websockets/

:働いていない、あなたのコードの特定の部分に向けて

var websocket = new WebSocket("ws://myapp-myname.rhcloud.com:8000"); 
websocket.onopen = function(event) { 
    // The connection was opened 
    console.log(event) 
}; 
websocket.onclose = function(event) { 
    // The connection was closed 
    console.log(event) 
}; 
websocket.onmessage = function(event) { 
    // New message arrived 
    message = event.data 
    console.log(event) 
}; 
websocket.onerror = function(event) { 
    // There was an error with your WebSocket 
    console.log(event) 
}; 

上記少なくとも役立つかもしれないポイントあなたを

そうでない場合は、openshiftのブログで提供されている例を試してみてください。あるいは、この例がうまくいかない場合は、カートリッジに問題がある可能性があり、RedHatのサポートに手を差し伸べることができます。