码迷,mamicode.com
首页 > Web开发 > 详细

WebSocket

时间:2020-01-08 17:15:44      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:ice   receive   使用   ble   com   ini   width   连接   dev   

<!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>

WebSocket

标签:ice   receive   使用   ble   com   ini   width   连接   dev   

原文地址:https://www.cnblogs.com/shenjilin/p/12167678.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!