Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid errors when connection is reset (as when using self-signed cert…
…ificate for wss)
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Simple websocket secure test</title> | ||
<script> | ||
var conn = new WebSocket("wss://127.0.0.1:8001") | ||
|
||
conn.onopen = function () { | ||
console.log("Connection opened") | ||
conn.send("hello world") | ||
} | ||
|
||
conn.onclose = function () { | ||
console.log("Connection closed") | ||
} | ||
|
||
conn.onmessage = function (evt) { | ||
console.info("Received "+evt.data) | ||
conn.close() | ||
} | ||
|
||
conn.onerror = function () { | ||
console.error("Error") | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<p><strong>Notes:</strong></p> | ||
<ol> | ||
<li>Open web console</li> | ||
<li>Run index.js script with nodejs</li> | ||
<li>Access "https://127.0.0.1:8001" in another tab. The browser should alert you about security, since the certificate is self-signed</li> | ||
<li>Accept security exception and close that tab</li> | ||
<li>Reload this page</li> | ||
</ol> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var fs = require('fs') | ||
var ws = require('../../') | ||
|
||
// See http://www.nodejs.org/api/tls.html for info on how to create key and certificate files | ||
var options = { | ||
secure: true, | ||
key: fs.readFileSync("key.pem"), | ||
cert: fs.readFileSync("cert.pem") | ||
} | ||
|
||
ws.createServer(options, function (conn) { | ||
conn.on("text", function (str) { | ||
conn.sendText(str.toUpperCase() + "!!!") | ||
}) | ||
}).listen(8001, "127.0.0.1") |