WebSocket
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebSocket</title>
</head>
<body>
</body>
<script>
var ids = 12;
var ws = new WebSocket(‘ws://192.168.2.161:8080/webSocket?id=‘ + ids);
// console.log(Socket)
ws.onopen = function () {
// 使用 send() 方法发送数据
ws.send(‘发送数据‘)
alert(‘数据发送中...‘)
}
//7接受服务端数据时触发事件
ws.onmessage = function(evt) {
var received_msg = evt.data;
console.log(evt)
console.log(‘数据已接受‘)
}
//断开 web socket 连接成功触发事件
ws.onclose = function() {
console.log(‘连接已关闭.....‘)
}
</script>
</html>
相关推荐
柳木木的IT 2020-11-04
joynet00 2020-09-23
wenf00 2020-09-14
蓝色深海 2020-08-16
wuychn 2020-08-16
取个好名字真难 2020-08-06
darylove 2020-06-26
shufen0 2020-06-20
Lovexinyang 2020-06-14
WangBowen 2020-06-14
firejq 2020-06-14
hjhmpl 2020-06-14
水痕 2020-06-07
guozewei0 2020-06-06
woniyu 2020-06-02
取个好名字真难 2020-06-01
guozewei0 2020-05-28
woniyu 2020-05-26