summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2019-05-15 04:19:12 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-05-14 15:19:11 -0400
commite3e9269c76299df99975e17a04b4d1b1ca39dfcb (patch)
treec0bab4773a25589edaea12287c6a8422bd5208f1 /examples
parenta3de8c3d8a376049a37f8193c8538acc0d7a88f3 (diff)
feat: ws client (denoland/deno_std#394)
Original: https://github.com/denoland/deno_std/commit/782e3f690ffb9ee0dd89a5a64a3f2b753899719b
Diffstat (limited to 'examples')
-rw-r--r--examples/ws.ts39
1 files changed, 0 insertions, 39 deletions
diff --git a/examples/ws.ts b/examples/ws.ts
deleted file mode 100644
index f5965b7eb..000000000
--- a/examples/ws.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { serve } from "https://deno.land/std/http/mod.ts";
-import {
- acceptWebSocket,
- isWebSocketCloseEvent,
- isWebSocketPingEvent
-} from "https://deno.land/std/ws/mod.ts";
-
-async function main(): Promise<void> {
- console.log("websocket server is running on 0.0.0.0:8080");
- for await (const req of serve("0.0.0.0:8080")) {
- if (req.url === "/ws") {
- (async (): Promise<void> => {
- const sock = await acceptWebSocket(req);
- console.log("socket connected!");
- for await (const ev of sock.receive()) {
- if (typeof ev === "string") {
- // text message
- console.log("ws:Text", ev);
- await sock.send(ev);
- } else if (ev instanceof Uint8Array) {
- // binary message
- console.log("ws:Binary", ev);
- } else if (isWebSocketPingEvent(ev)) {
- const [, body] = ev;
- // ping
- console.log("ws:Ping", body);
- } else if (isWebSocketCloseEvent(ev)) {
- // close
- const { code, reason } = ev;
- console.log("ws:Close", code, reason);
- }
- }
- })();
- }
- }
-}
-
-main();