1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00
denoland-deno/ext/websocket/autobahn/autobahn_server.js

21 lines
484 B
JavaScript
Raw Normal View History

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { parse } from "../../../test_util/std/flags/mod.ts";
const { port } = parse(Deno.args, {
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;
});