企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ <!DOCTYPE html> <html> <head> <title>WebSocket Example</title> </head> <body> <h1>WebSocket Example</h1> <div id="output"></div> <script> const output = document.getElementById('output'); const ws = new WebSocket('ws://localhost:8080/websocket'); ws.onopen = (event) => { output.innerHTML += '<p>WebSocket is open.</p>'; }; ws.onmessage = (event) => { output.innerHTML += `<p>Received: ${event.data}</p>`; }; ws.onclose = (event) => { if (event.wasClean) { output.innerHTML += `<p>WebSocket closed cleanly, code=${event.code}, reason=${event.reason}</p>`; } else { output.innerHTML += '<p>Connection was abruptly closed.</p>'; } }; ws.onerror = (error) => { output.innerHTML += `<p>WebSocket error: ${error.message}</p>`; }; </script> </body> </html> ~~~