Skip to content

Instantly share code, notes, and snippets.

@treeform
Created November 12, 2019 22:33
Show Gist options
  • Save treeform/1f28dafa53925ba6c56d698a999c5f7a to your computer and use it in GitHub Desktop.
Save treeform/1f28dafa53925ba6c56d698a999c5f7a to your computer and use it in GitHub Desktop.
import ws, asyncdispatch, asynchttpserver
proc cb(req: Request) {.async.} =
var ws = await newWebSocket(req)
echo "Got ws connecting with protocol ", ws.protocol
if ws.protocol == "alpha":
await ws.send("Welcome Protocol Alpha")
ws.close()
var server = newAsyncHttpServer()
waitFor server.serve(Port(9001), cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment