// 测试webSocket $(document).ready(function() { var webSocket = null ; testWebSocket(); }) function testWebSocket(){ var currentLoginName = '${fns:getUser().loginName}'; var pathName = window.document.location.pathname; var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); var url = "ws://"+window.location.host+projectName+"/testWebSocketByYz" ; webSocket = new WebSocket(url); webSocket.onopen = function(event){ webSocket.send(currentLoginName); console.log(url+"已连接!"); } webSocket.onerror = function(event){ console.log(url+"连接发生错误,请刷新页面重试!"); } webSocket.onmessage = function(event){ console.log(event); } window.onbeforeunload = function(){ webSocket.close(); } } |
webSocket整理 (实例篇--Jsp)
最新推荐文章于 2025-07-03 15:29:25 发布