javascript - Secure WebSocket fail to connection - 1001 server error -
i have create simple websocket server ssl certificate (self signed). server created in delphi. if try connect on server delphi client application connection works. if try connect on server html5/javascript program, server return error "1001-going away" javascript program works address "ws://localhost:777/" (and server without tls logic) don't work "wss://localhost:777/" address.
i paste program code:
<!doctype html> <meta charset="utf-8" /> <title>websocket test</title> <script language="javascript" type="text/javascript"> var wsuri = "wss://localhost:777/"; var output; function init() { output = document.getelementbyid("output"); testwebsocket(); } function testwebsocket() { websocket = new websocket(wsuri); websocket.onopen = function(evt) { onopen(evt) }; websocket.onclose = function(evt) { onclose(evt) }; websocket.onmessage = function(evt) { onmessage(evt) }; websocket.onerror = function(evt) { onerror(evt) }; } function onopen(evt) { writetoscreen("connected"); dosend("websocket rocks"); } function onclose(evt) { writetoscreen("disconnected"); } function onmessage(evt) { writetoscreen('<span style="color: blue;">response: ' + evt.data+'</span>'); websocket.close(); } function onerror(evt) { writetoscreen('<span style="color: red;">error:</span> ' + evt.data); } function dosend(message) { writetoscreen("sent: " + message); websocket.send(message); } function writetoscreen(message) { var pre = document.createelement("p"); pre.style.wordwrap = "break-word"; pre.innerhtml = message; output.appendchild(pre); } window.addeventlistener("load", init, false); </script> <h2>websocket test</h2> <div id="output"></div>
please, can explain why situation happen , how can solve problem? thanks
Comments
Post a Comment