当前位置: 移动技术网 > 网络运营>网络>协议 > websocket服务器握手协议测试网页代码

websocket服务器握手协议测试网页代码

2018年03月26日  | 移动技术网网络运营  | 我要评论

测试网页代码如下

<!DOCTYPE html>  
<html>  
<head>  
    <title>测试 websocket 世界最简单案例</title>  
</head>  
<body>  
    <script>  
    var ws = new WebSocket("ws://127.0.0.1:8001/");  
      
    ws.onopen = function(){  
        alert("open");  
        ws.send("WebSocket");  
    };  
    ws.onmessage = function(ev){  
        alert(ev.data);  
    };  
    ws.onclose = function(ev){  
        alert("close");  
    };  
    ws.onerror = function(ev){  
        console.log(ev);  
        alert("error");  
    };  
    </script>  
</body>  
</html>  

\

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网