2014-09-18 91 views
0

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

回答

0

var ws = new WebSocket("wss://localhost:8080/websocket/echo");必须改变,以正在使用本地主机在这种情况下是8443端口所以现在应该读var ws = new WebSocket("wss://localhost:8443/websocket/echo");

相关问题