1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 01:58:05 -05:00
denoland-deno/cli/bench/websocket/deno_echo.js

26 lines
528 B
JavaScript
Raw Normal View History

// 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;
}
2023-04-26 15:09:28 -04:00
serve({ port: parseInt(port), hostname: "0.0.0.0" }, handler);