https://github.com/drowzy/ex_wss
Elixir websocket server
https://github.com/drowzy/ex_wss
cowboy elixir websocket
Last synced: 3 months ago
JSON representation
Elixir websocket server
- Host: GitHub
- URL: https://github.com/drowzy/ex_wss
- Owner: drowzy
- Created: 2017-02-04T23:34:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-16T15:09:26.000Z (over 8 years ago)
- Last Synced: 2025-02-16T11:14:09.845Z (8 months ago)
- Topics: cowboy, elixir, websocket
- Language: Elixir
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ExWss
Elixir Websocket server using, plug and cowboy.
Built because I wanted hands on experience implementing a websocket server in Elixir
without using Phoenix.## Installation
Requires Elixir >= 1.4.0```bash
git clone https://github.com/drowzy/ex_wss```
## Usage
Run with:
```bash
iex -S mix
```The HTTP server is listening on port 4444 by default. The websocket endpoint is located at ws://localhost:4444/ws
Connected clients are closed if inactive longer than 60s. This can be changed in `config/config.exs` together with `port` and `ws_endpoint`.This implementation specifies a simple pubsub protocol where the client can subscribe to a topic and broadcast messages to a topic.
### Subscribing
A subscription to a topic can be done by sending a message on the form:
```json
{
"type": "subscribe",
"topic": "foo.bar"
}
```
The message is either acked or nacked depending on outcome. Trying to subscribe to the same topic twice will result in a nack the second time.### Publishing
A Publish is done by sending:```json
{
"type": "publish",
"topic": "foo.bar",
"payload": "baz"
}
```The message will be broadcasted to all subscribers on the topic, the request will always be acked.