mirror of
https://github.com/denoland/deno.git
synced 2025-08-02 18:12:39 +00:00
chore(cli/bench): add ws echo bench (#18595)
This commit is contained in:
parent
db39855fcb
commit
34d596e04f
5 changed files with 112 additions and 2 deletions
25
cli/bench/websocket/deno_echo.js
Normal file
25
cli/bench/websocket/deno_echo.js
Normal 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" });
|
Loading…
Add table
Add a link
Reference in a new issue