chore(cli/bench): add ws echo bench (#18595)

This commit is contained in:
Divy Srivastava 2023-04-05 18:31:07 +05:30 committed by GitHub
parent db39855fcb
commit 34d596e04f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 112 additions and 2 deletions

View file

@ -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" });