websocket页面配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function websocketDemo(){
if('WebSocket' in window){
console.log('支持');
var ws = new WebSocket('ws://192.168.101.173:8077/test/ws.py');
ws.open = function(){
ws.send('发送数据');
alert('发送数据中...');
};
ws.onmessage = function(evt){
var msg = evt.data;
alert('数据已接收...');
}
ws.onclose = function(){
alert('连接关闭...');
}
}
}
websocketDemo();