2014-07-24 87 views
1

我的代碼後的WebSocket錯誤連接到Websocket端點的JavaScript:當部署在本地部署到Openshift

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

我部署這OpenshiftURL變化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] 

在那裏我看到

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

什麼是可能的問題嗎?

回答

3

你需要讓你的應用程序URL的WebSocket連接到端口8000,而不是80端口

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