12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Netty WebSocket 时间服务器</title>
- </head>
- <body>
- Netty WebSocket 时间服务器
- <br>
- <script type="text/javascript">
- var socket;
- if (!window.WebSocket) {
- window.WebSocket = window.MozWebSocket;
- }
- if (window.WebSocket) {
- socket = new WebSocket("ws://192.168.3.96:8088/onlinewebsocket/123123123");
- socket.onmessage = function (event) {
- var ta = document.getElementById('responseText');
- ta.value = "";
- ta.value = event.data
- };
- socket.onopen = function (event) {
- var ta = document.getElementById('responseText');
-
- };
- socket.onclose = function (event) {
- console.log(event)
- var ta = document.getElementById('responseText');
- ta.value = "";
- ta.value = "WebSocket 关闭!";
- };
- }
- else {
- alert("抱歉,您的浏览器不支持WebSocket协议!");
- }
- function send(message) {
- if (!window.WebSocket) {
- return;
- }
- if (socket.readyState == WebSocket.OPEN) {
- var requestHeader = {'key1': 'value1', 'key2': 'value2'};
-
- socket.send(message);
- // socket.send(JSON.stringify({'request_header': requestHeader}));
- }
- else {
- alert("WebSocket连接没有建立成功!");
- }
- }
- </script>
- <form onsubmit="return false;">
- <input type="text" name="message" value="Netty最佳实践"/>
- <br><br>
- <input type="button" value="发送WebSocket请求消息" onclick="send(this.form.message.value)" />
- <input type="button" value="关闭" onclick="socket.close()" />
- <hr color="blue"/>
- <h3>服务端返回的应答消息</h3>
- <textarea id="responseText" style="width:500px;height:300px;"></textarea>
- </form>
- </body>
- </html>
|