# \[ANN\] SimpleWebsockets - renamed from \`Websocket\`

**URL:** <https://discourse.julialang.org/t/ann-simplewebsockets-renamed-from-websocket/48050>\
**Category:** Package Announcements\
**Created:** [October 9, 2020, 4:28pm UTC](https://discourse.julialang.org/t/ann-simplewebsockets-renamed-from-websocket/48050 "2020-10-09T16:28:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![citkane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/citkane/32/17595_2.png) [@citkane](https://discourse.julialang.org/u/citkane)\
**Post date:** [October 9, 2020, 4:28pm UTC](https://discourse.julialang.org/t/ann-simplewebsockets-renamed-from-websocket/48050/1 "2020-10-09T16:28:06Z")

</div>

# SimpleWebsockets.jl

[![Build Status](https://travis-ci.org/citkane/SimpleWebsockets.jl.svg?branch=master)](https://travis-ci.org/citkane/SimpleWebsockets.jl) [![Coverage Status](https://coveralls.io/repos/github/citkane/SimpleWebsockets.jl/badge.svg?branch=master)](https://coveralls.io/github/citkane/SimpleWebsockets.jl?branch=master) [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://citkane.github.io/SimpleWebsockets.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://citkane.github.io/SimpleWebsockets.jl/dev) [![GitHub Repo stars](https://img.shields.io/github/stars/citkane/SimpleWebsockets.jl?style=social)](https://github.com/citkane/SimpleWebsockets.jl)

This is a rename of [Websocket](https://discourse.julialang.org/t/ann-websocket-high-level-api-for-server-and-client-with-documentation/47957) in order to avoid confusion with the existing `WebSockets` package.

```julia
using Pkg
Pkg.add("SimpleWebsockets")

```

## Basic usage server:

```julia
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
    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:

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

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

```

---

<div class="post-metadata">

**Author:** ![Jon\_Norberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jon_norberg/32/3218_2.png) [@Jon\_Norberg](https://discourse.julialang.org/u/Jon_Norberg)\
**Post date:** [October 14, 2020, 10:20am UTC](https://discourse.julialang.org/t/ann-simplewebsockets-renamed-from-websocket/48050/2 "2020-10-14T10:20:20Z")

</div>

This looks very nice. What would you say is the biggest difference to the WebSockets package in terms of use and development philosophy you applied?

---

<div class="post-metadata">

**Author:** ![citkane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/citkane/32/17595_2.png) [@citkane](https://discourse.julialang.org/u/citkane)\
**Post date:** [October 14, 2020, 2:31pm UTC](https://discourse.julialang.org/t/ann-simplewebsockets-renamed-from-websocket/48050/3 "2020-10-14T14:31:00Z")

</div>

Thanks @Jon_Norberg

I started out on this package because I needed a WS client that could deal with high frequency (`ms`) market data streaming.

It was also very important that I was able to reliably, instantly reconnect on requests from the server, data frame errors and network errors. As such, I needed informative error reporting and event hooks at an API level to decide what actions my application should take.

I started by trying to wrap an API around existing solutions, but it became apparent that Julia Async behavior is a powerful, tricky, fickle beast… Existing solutions had pretty dense, monolithic architectures.

This prompted me to start from scratch and port a WS architecture I was familiar with from the Node.js [websocket](https://www.npmjs.com/package/websocket) package. This is predominantly OOP with a well documented and flexible high level API - something which is mirrored in SimpleWebsockets.jl

What I have now is working well for me. I hope that over time a few more souls will find it handy and start refining these particular points of development:

- Memory allocation. I have done my best to allow for minimal IO buffer allocations and reuse of these allocations under all circumstances. This may still be sub-optimal in the server context, especially a generous incoming message buffer for each connected client instance. I have no idea how well this is going to scale.
- Better test coverage - async, tricksy tricksy. I am at 86%, but with better thought this can improve a lot. I just don’t have the immediate resources.
- [Autobahn testing](https://github.com/crossbario/autobahn-testsuite) - again, time and resources.

Also - websocket extensions are not implemented. This is mostly because I need to research what these are and exactly how they work. I have had no need for them in my work yet.
