aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-05-10 11:29:17 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-05-10 11:29:17 +0200
commiteabb52a6c0028bc4e4bf9cb1cf1add28ab3df185 (patch)
tree14cdbd56685be7a82a2a2ebc51cfbfec8c9807db /examples
parentdf4a36990c799901463d63c78de0f0672b675688 (diff)
downloadtricot-eabb52a6c0028bc4e4bf9cb1cf1add28ab3df185.tar.gz
tricot-eabb52a6c0028bc4e4bf9cb1cf1add28ab3df185.zip
Doc + example + fix domain/host bug
Diffstat (limited to 'examples')
-rw-r--r--examples/.gitignore1
-rw-r--r--examples/node/client.mjs11
-rw-r--r--examples/node/package-lock.json44
-rw-r--r--examples/node/package.json14
-rw-r--r--examples/node/server.mjs9
5 files changed, 79 insertions, 0 deletions
diff --git a/examples/.gitignore b/examples/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/examples/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/examples/node/client.mjs b/examples/node/client.mjs
new file mode 100644
index 0000000..2a10d1e
--- /dev/null
+++ b/examples/node/client.mjs
@@ -0,0 +1,11 @@
+import WebSocket from 'ws';
+
+const u = 'wss://localhost:4443';
+//const u = 'ws://localhost:3000';
+
+const ws = new WebSocket(u, {
+ rejectUnauthorized: false,
+});
+
+ws.on('open', () => ws.send('something'))
+ws.on('message', msg => console.log('received: %s', msg))
diff --git a/examples/node/package-lock.json b/examples/node/package-lock.json
new file mode 100644
index 0000000..8e0f855
--- /dev/null
+++ b/examples/node/package-lock.json
@@ -0,0 +1,44 @@
+{
+ "name": "nodeserver",
+ "version": "1.0.0",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "nodeserver",
+ "version": "1.0.0",
+ "license": "AGPL-3.0-or-later",
+ "dependencies": {
+ "ws": "^8.6.0"
+ }
+ },
+ "node_modules/ws": {
+ "version": "8.6.0",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz",
+ "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==",
+ "engines": {
+ "node": ">=10.0.0"
+ },
+ "peerDependencies": {
+ "bufferutil": "^4.0.1",
+ "utf-8-validate": "^5.0.2"
+ },
+ "peerDependenciesMeta": {
+ "bufferutil": {
+ "optional": true
+ },
+ "utf-8-validate": {
+ "optional": true
+ }
+ }
+ }
+ },
+ "dependencies": {
+ "ws": {
+ "version": "8.6.0",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz",
+ "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==",
+ "requires": {}
+ }
+ }
+}
diff --git a/examples/node/package.json b/examples/node/package.json
new file mode 100644
index 0000000..83f5cb7
--- /dev/null
+++ b/examples/node/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "nodeserver",
+ "version": "1.0.0",
+ "description": "",
+ "main": "server.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "Quentin Dufour <quentin@deuxfleurs.fr>",
+ "license": "AGPL-3.0-or-later",
+ "dependencies": {
+ "ws": "^8.6.0"
+ }
+}
diff --git a/examples/node/server.mjs b/examples/node/server.mjs
new file mode 100644
index 0000000..474ebe0
--- /dev/null
+++ b/examples/node/server.mjs
@@ -0,0 +1,9 @@
+import { WebSocketServer } from 'ws';
+
+const wss = new WebSocketServer({ port: 3000 });
+
+wss.on('connection', ws =>
+ ws.on('message', msg => {
+ console.log('received: %s', msg)
+ ws.send(msg)
+}))