1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 02:29:06 -05:00
denoland-deno/cli/bench/websocket/deno_echo.js
2023-04-05 18:31:07 +05:30

25 lines
528 B
JavaScript

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