[ANN] Websocket - High level API for Server and Client with documentation

Websocket.jl

Github Code

Why another Websocket package?

The existing Julia websocket solutions are in various states of development and lack comprehensive high level API’s comparable to offerings in other languages such as JS and Python.

For this reason I have ported the architecture of the popular Node.js websocket package into Julia.

Basic usage server:

using Websocket

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
    logWSerror(err)
    notify(ended, err.msg, 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 Websocket

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
    logWSerror(err)
    notify(ended, err.msg, error = true)
end

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

Nice! I’m super excited to take this for a spin!!

1 Like

I just added:

as v0.0.3 which builds documentation as a Github Page.

This documentation has source links @ bottom right of code snippets, whereas the Juliahub documentation build appears to omit the link.

I have been asked nicely by a human at JuliaRegistry to rename this package because of potential confusion with the existing WebSockets package.

This package is now called SimpleWebsockets and should appear on the registry shortly.

Websocket will be deprecated shortly in favor of SimpleWebsockets. (once I have figured out how to do that!)

2 Likes

@avik
Could you help with deprecating the old package please.
I am looking at this post , but am a bit confused.

Setting the upper bound: I assume this is in Project.toml [compat] - could you give an example of the value

just send a PR to metadata to add the upper bound to all released versions of the package.

Any idea how to do that?

Or is there a formal way to do the whole deprecation procedure?