summaryrefslogtreecommitdiff
path: root/cli/bench/websocket
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-04-05 18:31:07 +0530
committerGitHub <noreply@github.com>2023-04-05 18:31:07 +0530
commit34d596e04f49400ed6460e03461e21c441bcb5dd (patch)
treeda465892b423c0b47eb9c70a4869b7cb25383302 /cli/bench/websocket
parentdb39855fcb9e90131432d1c03bd5c16263addb3e (diff)
chore(cli/bench): add ws echo bench (#18595)
Diffstat (limited to 'cli/bench/websocket')
-rw-r--r--cli/bench/websocket/deno_echo.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/bench/websocket/deno_echo.js b/cli/bench/websocket/deno_echo.js
new file mode 100644
index 000000000..70e64dcbe
--- /dev/null
+++ b/cli/bench/websocket/deno_echo.js
@@ -0,0 +1,25 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+const port = Deno.args[0] ?? "8080";
+const { serve } = Deno;
+
+function handler(request) {
+ const { socket, response } = Deno.upgradeWebSocket(request, {
+ idleTimeout: 0,
+ });
+ socket.onmessage = (e) => {
+ socket.send(e.data);
+ };
+
+ socket.onopen = () => {
+ console.log("Connected to client");
+ };
+
+ socket.onerror = (e) => {
+ console.log(e);
+ };
+
+ return response;
+}
+
+serve(handler, { port: parseInt(port), hostname: "0.0.0.0" });