zoukankan      html  css  js  c++  java
  • 这个表明将http协议转成websocket协议

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>websocket</title>
        <script>
            var socket;
            if (window.WebSocket){
                socket=new WebSocket('ws://127.0.0.1:8899/ws')
                socket.onmessage=function (ev) { //接收到消息
                    var ts=document.getElementById('responseTest');
                    ts.value+='
    '+ev.data;
                }
                socket.onopen=function (ev) {
                    var ts=document.getElementById('responseTest');
                    ts.value+='连接开启';
                }
                socket.onclose=function (ev) {
                    var ts=document.getElementById('responseTest');
                    ts.value+='
    连接关闭';
                }
            } else {
                alert('浏览器不支持websocket');
            }
            function send(message) {
                if (!window.WebSocket){
                    return;
                }
                if(socket.readyState == WebSocket.OPEN){
                    socket.send(message);
                }else {
                    alert('连接尚未开启');
                }
            }
        </script>
    </head>
    <body>
    
    <form onsubmit="return false">
        <textarea  name="message" style=" 400px;height: 200px;"></textarea>
        <input type="button" value="发送消息" onclick="send(this.form.message.value)">
        <h3>服务输出</h3>
        <textarea  id="responseTest" style=" 400px;height: 300px;"></textarea>
        <input type="button" value="清空消息" onclick="javascript:document.getElementById('responseTest').value=''">
    </form>
    
    </body>
    </html>
  • 相关阅读:
    LeetCode 453 Minimum Moves to Equal Array Elements
    LeetCode 112 Path Sum
    LeetCode 437 Path Sum III
    LeetCode 263 Ugly Number
    Solutions and Summay for Linked List Naive and Easy Questions
    AWS–Sysops notes
    Linked List
    All About Linked List
    datatable fix error–Invalid JSON response
    [转]反编译c#的相关问题
  • 原文地址:https://www.cnblogs.com/dongma/p/10206006.html
Copyright © 2011-2022 走看看