2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-07-25 01:30:28 -04:00
|
|
|
import { parseArgs } from "@std/cli/parse-args";
|
2023-05-01 08:37:32 -04:00
|
|
|
|
2024-07-25 01:30:28 -04:00
|
|
|
const { port } = parseArgs(Deno.args, {
|
2023-05-01 08:37:32 -04:00
|
|
|
number: ["port"],
|
|
|
|
default: {
|
|
|
|
port: 6969,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { serve } = Deno;
|
|
|
|
|
|
|
|
// A message-based WebSocket echo server.
|
|
|
|
serve({ port }, (request) => {
|
|
|
|
const { socket, response } = Deno.upgradeWebSocket(request);
|
|
|
|
socket.onmessage = (event) => {
|
|
|
|
socket.send(event.data);
|
|
|
|
};
|
|
|
|
return response;
|
|
|
|
});
|