123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <title></title>
- </head>
- <body>
- <script type="text/javascript">
- var socket;
- var messageNum=0;
- if (!window.WebSocket) {
- window.WebSocket = window.MozWebSocket;
- }
- if (window.WebSocket) {
- // socket = new WebSocket("ws://127.0.0.1:8390?group_id=1");
- socket = new WebSocket("ws://test-ws.meechat.club?group_id=1");
- socket.onmessage = function(event) {
- messageNum = messageNum+1;
- var ta = document.getElementById('responseText');
- ta.value=messageNum
- };
- socket.onopen = function(event) {
- var ta = document.getElementById('responseText');
- ta.value = "连接开启!\n";
- };
- socket.onclose = function(event) {
- var ta = document.getElementById('responseText');
- ta.value = ta.value + "连接关闭\n";
- };
- } else {
- alert("您的浏览器不支持 WebSocket!");
- }
- function send(message) {
- if (!window.WebSocket) {
- return;
- }
- if (socket.readyState == WebSocket.OPEN) {
- socket.send(message);
- } else {
- alert("连接没有开启");
- }
- }
- </script>
- <form onsubmit="return false;">
- <h3></h3>
- <textarea id="responseText" style="width: 500px; height: 300px;"></textarea>
- <br>
- <input type="text" name="message" style="width: 300px" value="websocket连接工具">
- </form>
- <br>
- <br>
- </body>
- </html>
|