zoukankan      html  css  js  c++  java
  • websocket client code html

    <!doctype html>

    <html lang="en">

    <head>

        <meta charset="UTF-8">

        <title>Document</title>

        <style>

            .kuang{text-align: center;margin-top:200px;}

        

    #mess{text-align: left}

    </style>

    </head>

    <body>

    <input id="t1" type=text value="ls" onkeydown="KeyDown();"/> 

    <input type=button value="runShell" onclick="aa();">

    <div id="mess"></div>

        <script>

            var mess = document.getElementById("mess");

            if(window.WebSocket){

                var ws = new WebSocket('ws://127.0.0.1:8002');

                ws.onopen = function(e){

                    console.log("连接服务器成功");

                    ws.send("ls");

                }

                ws.onclose = function(e){

                    console.log("服务器关闭");

                }

                ws.onerror = function(){

                    console.log("连接出错");

                }

                ws.onmessage = function(e){

                    //mess.innerHTML = "连接成功"

    var time = new Date();

    mess.innerHTML+=(e.data+"<br>");

                    

                }

            }

    function aa(){

    var t = document.getElementById("t1");

    console.log(t.value);

    ws.send(t.value,"ff");

    }

    function KeyDown()

    {

      if (event.keyCode == 13)

      {

        event.returnValue=false;

        event.cancel = true;

        aa();

      }

    }

        </script>

    </body>

    </html>

  • 相关阅读:
    面试题
    ajax部分
    jquery部分
    javascript部分
    webpack入门
    jQuery 实现下载进度条
    webSocket入门
    Ajax实现下载进度条
    C# IDisposable接口
    nuget必备插件(待续)
  • 原文地址:https://www.cnblogs.com/wblade/p/8975695.html
Copyright © 2011-2022 走看看