websocket html

var ws = new WebSocket('ws://127.0.0.1:8000/ws');

ws.onopen = function() {

alert("open");

ws.send("WebSocket");

};

ws.onmessage = function(ev) {

alert(ev.data);

};

ws.onclose = function(ev) {

alert("close");

};

ws.onerror = function(ev) {

alert("error");

};

你可能感兴趣的:(websocket html)