You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
continuous-integration/drone/push Build is passing
Details
|
2 years ago | |
---|---|---|
.. | ||
src | 2 years ago | |
Cargo.toml | 2 years ago | |
README.md | 2 years ago |
README.md
WebSocket server implementation
This crate provides a WebSocket server for the Scrabble with numbers game.
Build
This project uses Cargo, so ensure you have it installed.
cargo build --release
Usage
The server listens on port 8080
by default. You can change this by specifying a program argument:
# Run a debug build on port 1234
cargo run -- '0.0.0.0:1234'
# Run an already built binary on the default port
./board-server
Protocol
The server only understands certain predefined messages. All messages are sent as JSON strings are can only be sent by either the client or the server.
You can see the exact layout of the messages in the protocol file.
Messages sent and received shouldn't contain any unnecessary indentation.
Sample client
// Create WebSocket connection.
const socket = new WebSocket('ws://localhost:8080');
// Connection opened
socket.addEventListener('open', (event) => {
// Create a new room, and join it it immediately with the player name "player_name"
// The server will respond with a JoinedRoom message which contains the room name
socket.send(JSON.stringify({ CreateRoom: 'player_name' }));
});
// Listen for messages
socket.addEventListener('message', (event) => {
console.log('Message from server', JSON.parse(event.data));
});
Run as Linux service
[Unit]
Description=Scrabble with numbers - WebSocket Server
After=network.target
[Service]
ExecStart=board-server '0.0.0.0:21110'
[Install]
WantedBy=multi-user.target