我使用HTTPS https://localhost:8443/websocket/
连接到以下网站,该工作正常,可以正常使用我最新版本中的自签名证书Google Chrome。然而,当我试图通过下面的JavaScript代码通过我的页面上安全的WebSocket发送一条消息,我得到当我使用安全的WebSockets但一个WebSocket is already in CLOSING or CLOSED state
已关闭或已关闭模式下的安全websocket
<meta charset="utf-8"> <title>Tomcat WebSocket Chat</title> <script> var ws = new WebSocket("wss://localhost:8080/websocket/echo"); ws.onopen = function(){ }; ws.onmessage = function(message){ document.getElementById("chatlog").textContent += message.data + "\n"; }; function postToServer(){ ws.send(document.getElementById("msg").value); document.getElementById("msg").value = ""; } function closeConnect(){ ws.close(); } </script> </head> <body> <textarea id="chatlog" readonly></textarea><br/> <input id="msg" type="text" /> <button type="submit" id="sendButton" onClick="postToServer()">Send!</button> <button type="submit" id="sendButton" onClick="closeConnect()">End</button> </body> </html>
有没有人有一个线索,为什么发生这种情况代码在正常websockets的非HTTPS
页面上正常工作?它也正在通过tomcat 7.0.53
。