部署到Openshift后出现Websocket错误



本地部署时,我的代码连接到Websocket端点作为

 var connection = new WebSocket('ws://127.0.0.1:8080/tweetstream/tweets');  

我将其部署到Openshift, URL更改为http://map-tweetstream.rhcloud.com/tweetstream/

现在我开始看到WebSocket Error [object Event]错误,所以在Developer Tools(Chrome) -> Console中,我尝试连接到这个websocket作为

var connection = new WebSocket('ws://'+ document.location.host + document.location.pathname + 'tweets');
  connection.onopen = function() {
    connection.send('brazil');
  };
  connection.onerror = function(error) {
    console.log('WebSocket Error ' + error);
  };
  connection.onmessage = function(e) {
    var parse = JSON.parse(e.data);
    var coordinates = parse["geo"]["coordinates"];
    console.log("coordinates:" + JSON.stringify(coordinates, undefined, 2));
  };  

返回的是

WebSocket connection to 'ws://map-tweetstream.rhcloud.com/tweetstream/tweets' failed: Error during WebSocket handshake: Unexpected response code: 404
WebSocket Error [object Event]   

where I see

document.location.host
"map-tweetstream.rhcloud.com"
document.location.pathname
"/tweetstream/"  

这里可能的问题是什么?

您需要将websocket连接到应用程序url的端口8000,而不是端口80。

ws://map-tweetstream.rhcloud.com:8000/tweetstream/tweets

相关内容

  • 没有找到相关文章

最新更新