WebSocket server for Tech World that manages player connections and broadcasts movement/presence messages to all connected clients.
Built using shelf and shelf_web_socket.
- Manages WebSocket connections for multiple players
- Broadcasts player presence (arrivals/departures)
- Relays player movement paths to other connected clients
- SSL/TLS support for secure WebSocket connections (WSS)
- Dart SDK 3.0.0+
- SSL certificates for production deployment
dart pub getdart run bin/server.dartThe server requires SSL certificates at /app/cert.pem and /app/key.pem. For local development, you may need to modify these paths or generate self-signed certificates.
{
"name": "ws_game_server",
"request": "launch",
"type": "dart",
"program": "bin/server.dart"
}curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: localhost" -H "Origin: http://localhost" -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" http://localhost:8080dart test- bin/server.dart: Entry point, creates shelf server with SSL on port 443
- lib/client_connections_service.dart: Manages WebSocket connections, handles message routing
- lib/locator.dart: Service locator for dependency injection
- Client connects via WebSocket
- Client sends
arrivalmessage with user info - Server stores connection and broadcasts
other_usersto all clients - Server relays
player_pathmessages to other connected clients - On disconnect, server broadcasts updated
other_userslist
The CI/CD pipeline automatically deploys to a Compute Engine VM when you push a tagged commit:
git tag v1.0.0 && git push --tagsHow it works:
- Push a tagged commit
- GitHub Actions builds the Docker image and pushes to Artifact Registry
- The workflow SSHs into the VM and updates the running container
VM Details:
- Instance:
instance-20251007-053239 - Zone:
us-central1-a - Machine type:
e2-micro
Required GCP Permissions for GitHub Actions service account:
roles/artifactregistry.writer- push images to Artifact Registryroles/compute.instanceAdmin.v1- SSH into the VMroles/iap.tunnelResourceAccessor- tunnel through IAP (if enabled)
Setup References:
shelf: HTTP server frameworkshelf_web_socket: WebSocket support for shelfweb_socket_channel: WebSocket abstractionstech_world_networking_types: Shared message types