From f3437c710b86b8924c92a15477ecc20fa73b3a1b Mon Sep 17 00:00:00 2001 From: Sam O'Connor Date: Fri, 9 Nov 2018 08:30:01 +1100 Subject: [PATCH] WebSocket Example, See https://github.com/JuliaWeb/MbedTLS.jl/issues/186#issuecomment-435544863 --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 3f97a31a6..cf6c77412 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,26 @@ HTTP.serve() do request::HTTP.Request end ``` +## WebSocket Examples + +```julia +julia> @async HTTP.WebSockets.listen("127.0.0.1", UInt16(8081)) do ws + while !eof(ws) + data = readavailable(ws) + write(ws, data) + end + end + +julia> HTTP.WebSockets.open("ws://127.0.0.1:8081") do ws + write(ws, "Hello") + x = readavailable(ws) + @show x + println(String(x)) + end; +x = UInt8[0x48, 0x65, 0x6c, 0x6c, 0x6f] +Hello +``` + [docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg [docs-latest-url]: https://JuliaWeb.github.io/HTTP.jl/latest