это мой код из книг «Окончательное руководство по веб-сайту HTML5».почему Websocket onmessage не стреляет
....
<div id="output"></div>
<script>
function setup() {
output = document.getElementById("output");
ws = new WebSocket("ws://localhost:7777");
ws.onopen = function(e) {
log("Connected");
sendMessage("Hello Websocket!");
}
ws.onclose = function(e){
log("Disconnected: " + e.reason);
}
ws.onerror = function(e){
log("Error ");
}
ws.onmessage = function(e) {
log("Message received: " + e.data);
ws.close();
}
}
function sendMessage(msg){
ws.send(msg);
log("Message Sent");
}
function log(s){
var p = document.createElement("p");
p.style.wordWrap = "break-word";
p.textContent = s;
output.appendChild(p);
console.log(s);
}
setup();
</script>
, но, когда я бегу его в локальный .. выход только как этот
Connected
Message Sent
и прекратить до этого. Я знал, что событие onmessage не стреляет, но я не знаю, почему. что может быть проблемой? спасибо