zoukankan      html  css  js  c++  java
  • Websocket模板

    将代码复制,存到一个html文件中,打开即可。代码示例:

    <html>
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html;charset=gbk" />
    
    <title>Web sockets test</title>
    
    <script type="text/javascript">
    
    var ws;
    
    function Clicked() {
    
    try {
    
    ws = new WebSocket("ws:http://127.0.0.1:8080/SZYJ/getmoduleinfo?appid=1&ticket=wanli_127.0.0.1_1572340419452");//连接服务器
    
    //ws = new WebSocket("ws://echo.websocket.org/");//连接服务器
    
    //连接websocket
    
    ws.onopen = function(event, AlarmMessage) {
    
    alert("已经与服务器建立了连接rn当前连接状态:" + this.readyState);
    
    };
    
    //websocket传输数据
    
    ws.onmessage = function(event) {
    
    alert("接收到服务器发送的数据:rn" + event.data);
    
    var bjts = event.data;
    
    };
    
    //websocket关闭连接
    
    ws.onclose = function(event) {
    
    alert("已经与服务器断开连接rn当前连接状态:" + this.readyState);
    
    };
    
    //websocket连接异常
    
    ws.onerror = function(event) {
    
    alert("WebSocket异常!");
    
    };
    
    } catch (ex) {
    
    alert(ex.message);
    
    }
    
    };
    
    function seestate() {
    
    alert(ws.readyState);
    
    }
    
    </script>
    
    </head>
    
    <body>
    
    <button id='ToggleConnection' type="button" onclick='Clicked();'>连接服务器</button>
    
    <br />
    
    <br />
    
    <button id='ToggleConnection' type="button" onclick='seestate();'>查看状态</button>
    
    <br />
    
    <br />
    
    </body>
    
    </html>

    宁玉哥模板:

  • 相关阅读:
    [GL]行星运行1
    一个图的带权邻接表存储结构的应用
    [GDAL]3.影像金字塔构建
    [GDAL]1.GDAL1.8.1编译与第一个程序
    [GDAL]2.读取栅格和矢量数据
    C#迭代器
    GoogleEarth缓存机制探索
    AE开发三维的不足!
    [GDAL]4.影像的读取和显示
    [STL学习]1.概述
  • 原文地址:https://www.cnblogs.com/wanlige/p/12425044.html
Copyright © 2011-2022 走看看