当前位置:   article > 正文

jquery webSocket 调取接口获取通知_jquery.websocket.js

jquery.websocket.js
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>go测试socket</title>
</head>
<body>
<script type="text/javascript">
    var sock = null;
    //服务器的地址
    var wsuri = "ws://10.7.7.198:8081/websocket";
    window.onload = function() {
        console.log("onload");
        sock = new WebSocket(wsuri);
        sock.onopen = function() {
            //成功连接到服务器
            console.log("connected to " + wsuri);
        }
        sock.onclose = function(e) {
            console.log("connection closed (" + e.code + ")");
        }
        sock.onmessage = function(e) {
            //服务器发送通知
            //开始处理
            console.log("message received: " + e.data);
        }
    };

    function send() {
        var msg = document.getElementById('message').value;
        sock.send(msg);
    };

</script>
<h1>WebSocket Echo Test</h1>
<form>
    <p>
        Message: <input id="message" type="text" value="Hello, world!">
    </p>
</form>
<button onclick="send();">Send Message</button>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/1003961
推荐阅读