【发布时间】: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