1
我的代碼後的WebSocket錯誤連接到Websocket
端點的JavaScript:當部署在本地部署到Openshift
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]
在那裏我看到
document.location.host
"map-tweetstream.rhcloud.com"
document.location.pathname
"/tweetstream/"
什麼是可能的問題嗎?