WebSocket 原生socket实现,服务端和客户端以及 html 客户端 三端效果都可以测试

资源下载地址:https://download.csdn.net/download/kesshei/11256178

这个是 代码图,这个是效果图

___________常见WEB socket测试方案____________

websocket client  网页websocket

            var smartWebSocket = new SmartWebSocket("ws://127.0.0.1:9222/devtools/page/AF78F8D748482A79A9CAA0B801ABD43C");
            smartWebSocket.OnOpen += SmartWebSocketServer_OnOpen;
            smartWebSocket.OnClose += SmartWebSocketServer_OnClose;
            smartWebSocket.OnMessage += SmartWebSocketServer_OnMessage;
            smartWebSocket.Connect();
            Thread.Sleep(60000);
            smartWebSocket.SendMessage("{\r\n  \"method\": \"DOM.enable\",\r\n  \"id\": 4\r\n}");
            Console.WriteLine("服务启动,测试中!!");
            Console.ReadLine();
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>websocket client</title>
    <script type="text/javascript">
        var start = function () {
            var inc = document.getElementById('incomming');
            var wsImpl = window.WebSocket || window.MozWebSocket;
            var form = document.getElementById('sendForm');
            var input = document.getElementById('sendText');

            inc.innerHTML += "connecting to server ..<br/>";

            // create a new websocket and connect
            window.ws = new wsImpl('ws://localhost:9999/');

            // when data is comming from the server, this metod is called
            ws.onmessage = function (evt) {
                inc.innerHTML += evt.data + '<br/>';
            };

            // when the connection is established, this method is called
            ws.onopen = function () {
                inc.innerHTML += '.. connection open<br/>';
            };

            // when the connection is closed, this method is called
            ws.onclose = function () {
                inc.innerHTML += '.. connection closed<br/>';
            }

            form.addEventListener('submit', function (e) {
                e.preventDefault();
                var val = input.value;
                ws.send(val);
                input.value = "";
            });

        }
        window.onload = start;
    </script>
</head>
<body>
    <form id="sendForm">
        <input id="sendText" placeholder="Text to send" />
    </form>
    <pre id="incomming"></pre>
</body>
</html>

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝创精英团队

你的支持是我最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值