https://github.com/gonzofish/ws-chat-server
A small server for chatting through WebSockets
https://github.com/gonzofish/ws-chat-server
chat eventmachine ruby toy toy-project websocket websockets
Last synced: over 1 year ago
JSON representation
A small server for chatting through WebSockets
- Host: GitHub
- URL: https://github.com/gonzofish/ws-chat-server
- Owner: gonzofish
- Created: 2017-04-20T01:48:31.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-20T22:30:07.000Z (about 9 years ago)
- Last Synced: 2025-01-26T11:28:05.004Z (over 1 year ago)
- Topics: chat, eventmachine, ruby, toy, toy-project, websocket, websockets
- Language: Ruby
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WebSocket Chat Server
This is just a toy chat server I wrote to get more comfortable/reacquainted with WebSockets!
## Dependencies
The only dependency is the [EM-WebSocket library](https://github.com/igrigorik/em-websocket/).
To install it, just run:
```shell
gem install em-websocket
```
## Running the Server
To run the server:
```shell
ruby em-ws.rb
```
## Message Format
The format for a message, both to and from the client, is:
```typescript
{
type: string;
username: string;
value?: any;
}
```
All messages require a `type` and `username`, but only some messages will
provide or require a `value`.
To see the types of messages the client can send, please see
[Accepted Message Types](#client-types). For the types of messages the
server will send, please see [Response Types](#server-types).
Type|Purpose
---|---
`login`|Let's a user register their username, must be unique
`logout`|Unregister the username
`chat`|Send a chat message
All other types will result in a error message being returned.
Type|Purpose
---|---
`login_failure`|Username from a `login` is taken
`logged_in`|Username successfully registered
`chat`|A chat message was sent
`error`|An unknown message type was sent
All users receive the `chat` messages, but only the sending user will
receive the other three message types.