websocket服务器握手协议测试网页代码
程序员文章站
2022-03-27 21:29:39
测试网页代码如下
测试 w...
测试网页代码如下
<!DOCTYPE html> <html> <head> <title>测试 websocket 世界最简单案例</title> </head> <body> <script> var ws = new WebSocket("ws://127.0.0.1:8001/index.html"); 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>