SimpleWebsockets.jl

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

SimpleWebsockets.jl

CI codecov

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

Release 0.3 notes

0.3 upgrades the "HTTP" package dependency to major version 1 This breaks all functionality for Julia <=1.6

Installation

Pkg.add("SimpleWebsockets")

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.