SimpleWebsockets.jl

A flexible, powerful, high level interface for websocket SERVER and CLIENT in Julia.
Author citkane
Popularity
5 Stars
Updated Last
1 Year Ago
Started In
October 2020

SimpleWebsockets.jl

Build Status Coverage Status

A flexible, powerful, high level interface for Websockets in Julia. Provides a SERVER and CLIENT.

Basic usage server:

using SimpleWebsockets

server = WebsocketServer()
ended = Condition() 

listen(server, :client) do client
    listen(client, :message) do message
        @info "Got a message" client = client.id message = message
        send(client, "Echo back at you: $message")
    end
end
listen(server, :connectError) do err
    notify(ended, err, error = true)
end
listen(server, :closed) do details
    @warn "Server has closed" details...
    notify(ended)
end

@async serve(server; verbose = true)
wait(ended)

Basic usage client:

using SimpleWebsockets

client = WebsocketClient()
ended = Condition()

listen(client, :connect) do ws
    listen(ws, :message) do message
        @info message
    end
    listen(ws, :close) do reason
        @warn "Websocket connection closed" reason...
        notify(ended)
    end
    for count = 1:10
        send(ws, "hello $count")
        sleep(1)
    end
    close(ws)
end
listen(client, :connectError) do err
    notify(ended, err, error = true)
end

@async open(client, "ws://localhost:8080")
wait(ended)

Used By Packages

No packages found.