【问题标题】:secure websocket in closed or already closed mode在关闭或已关闭模式下保护 websocket
【发布时间】:2014-09-18 20:55:37
【问题描述】:

我使用 HTTPS https://localhost:8443/websocket/ 连接到以下站点,在最新的稳定版 Google Chrome 中使用我的自签名证书可以正常工作。但是,当我尝试通过页面上的安全 websocket 通过以下 JavaScript 代码发送消息时,我得到一个 WebSocket is already in CLOSING or CLOSED state

<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 时会发生这种情况,但代码在具有常规 websockets 的非HTTPS 页面上运行良好?它也正在通过tomcat 7.0.53运行。

【问题讨论】:

    标签: javascript tomcat ssl https websocket


    【解决方案1】:

    var ws = new WebSocket("wss://localhost:8080/websocket/echo"); 必须更改为用于本地主机的端口,在本例中为 8443,因此它现在应该显示为 var ws = new WebSocket("wss://localhost:8443/websocket/echo");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多