Websocket version 1.0 simple examples for local host

Maybe this one

julia> using Sockets

julia> using JSON

julia> pipe = ""

julia> if Sys.iswindows()
           pipe = "\\\\.\\pipe\\testsocket"
       else
           pipe = tempname()
       end
"/var/folders/3z/1kq4lzyd39l1c2gl5c0pzvy80000gp/T/julia0Q6Mrr"

julia> @async begin
           server = listen(pipe)
           while true
               sock = accept(server)
               @async while isopen(sock)
                   input = JSON.parse(sock)
                   JSON.print(sock, Dict("data" => rand(input["input"])))
              end
           end
       end
Task (runnable) @0x000000010b2a61d0

julia> clientside = connect(pipe)
Base.PipeEndpoint(RawFD(0x00000015) open, 0 bytes waiting)

julia> for i in 1:10
           JSON.print(clientside,Dict("input" => i))
           println(JSON.parse(clientside))
       end
Dict{String,Any}("data"=>Any[0.559774])
Dict{String,Any}("data"=>Any[0.89733, 0.513331])
Dict{String,Any}("data"=>Any[0.0675964, 0.381228, 0.618926])
Dict{String,Any}("data"=>Any[0.961195, 0.645998, 0.696614, 0.539933])
Dict{String,Any}("data"=>Any[0.927968, 0.328774, 0.969805, 0.959731, 0.169076])
Dict{String,Any}("data"=>Any[0.33247, 0.929461, 0.162861, 0.270243, 0.827589, 0.666108])
Dict{String,Any}("data"=>Any[0.0766846, 0.996563, 0.299863, 0.996271, 0.904049, 0.622786, 0.315614])
Dict{String,Any}("data"=>Any[0.245844, 0.991654, 0.590529, 0.515608, 0.557779, 0.331809, 0.0752659, 0.205465])
Dict{String,Any}("data"=>Any[0.841952, 0.514019, 0.676124, 0.668515, 0.72262, 0.231272, 0.425817, 0.512281, 0.949894])
Dict{String,Any}("data"=>Any[0.360244, 0.484267, 0.946671, 0.162157, 0.569451, 0.416769, 0.433126, 0.0784071, 0.432733, 0.521421])

julia> 
1 Like