LH_Jzs
2021-04-26 dcf5a87de927e683d4bbfad3978c3d608c06e48c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="utf-8">
 
</head>
 
<body>
    <div>
        <input style="width: max-content;" id="input_init" type="text">
        <input type="button" value="初始化" onclick="Init()">
    </div>
    <div>
        <input id="input_text" type="text">
        <input type="button" value="发送" onclick="Send()">
    </div>
    <script type="text/javascript">
        //高拍仪主服务指令控制地址
        var url = "ws://192.168.1.2:25014/";
        var ws_test;
        if ('WebSocket' in window) {
            ws_test = new WebSocket(url);
        }
        else if ('MozWebSocket' in window) {
            ws_test = new MozWebSocket(url);
        }
        else {
            alert("浏览器不支持WebSocket");
        }
        ws_test.onopen = function (evt) {
            console.log("Connection open ...");
            //ws.send("Hello WebSockets!");
        };
 
        ws_test.onmessage = function (evt) {
            console.log(evt.data);
            //ws.close();
        };
 
        ws_test.onclose = function (evt) {
            console.log("Connection closed.");
        };
        function Init() {
            var str = document.getElementById('input_init');
            console.log(str.value);
            ws_test.send(str.value);
        }
        function Send() {
            var str = document.getElementById('input_text');
            console.log(str.value);
            ws_test.send(str.value);
        }
    </script>
</body>
 
</html>