• e9_399234
    了解作者
  • 102.8KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-11 08:01
    上传日期
NULL 博文链接:https://zaq369cde.iteye.com/blog/1908461
websocket-demo.rar
  • client wesocket
  • index.html
    2.6KB
  • prototype.js
    136.6KB
  • java websocket.rar
    72.8KB
内容介绍
<!DOCTYPE html> <html> <head> <title>WebSocket Chat Client</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> document.observe("dom:loaded", function() { function log(text) { $("log").innerHTML = (new Date).getTime() + ": " + (!Object.isUndefined(text) && text !== null ? text : "null") +"<br>"+ $("log").innerHTML; } if (!window.WebSocket) { alert("FATAL: WebSocket not natively supported. This demo will not work!"); } var ws; $("uriForm").observe("submit", function(e) { e.stop(); ws = new WebSocket($F("uri")); ws.onopen = function() { log("[WebSocket#onopen]"); } ws.onmessage = function(e) { log("<b style='color:red;'>[WebSocket#onmessage] 接收消息:" + e.data + "</b>"); } ws.onclose = function() { log("[WebSocket#onclose]"); $("uri", "connect").invoke("enable"); $("disconnect").disable(); ws = null; } $("uri", "connect").invoke("disable"); $("disconnect").enable(); }); $("sendForm").observe("submit", function(e) { e.stop(); if (ws) { var textField = $("textField"); ws.send(textField.value); //log("[WebSocket#send] 发送消息:" + textField.value ); textField.value = ""; textField.focus(); } }); $("clear").observe("click", function(e) { $("log").innerHTML =''; }); $("disconnect").observe("click", function(e) { e.stop(); if (ws) { ws.close(); ws = null; } }); }); </script> </head> <body> <form id="uriForm"><input type="text" id="uri" value="ws://localhost:8887" style="width:200px;"> <input type="submit" id="connect" value="Connect"><input type="button" id="disconnect" value="Disconnect" disabled="disabled"></form><br> <form id="sendForm"><input type="text" id="textField" value="" style="width:200px;"> <input type="submit" value="Send"> <input type="button" id='clear' value="clear msg"></form><br> <form><div id="log" style="width:800px;heigth:450px" ></div></form><br> </body> </html>
评论
    相关推荐