我使用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
。