Fly.ioTutorial
WebSockets and Fly
Summary
Fly supports WebSocket connections, and the post demonstrates that support with flychat-ws, a small chat application built from raw WebSockets and Express. Deployment requires cloning the example, running npm install, then using flyctl init, flyctl deploy, and flyctl open, with no application-specific configuration changes. Its fly.toml maps internal TCP port 8080 to HTTP port 80 and TLS/HTTP port 443, sets concurrency limits of 20 soft and 25 hard, and checks the service every 10 seconds with a two-second timeout. The Node server broadcasts each received message to every connected client, while the browser selects ws or wss from the served protocol and sends JSON messages. TLS terminates at Fly’s network edge, and the app can also run locally or in Docker.
Context
The post addresses whether Fly supports WebSocket connections and uses a chat application to demonstrate long-lived, bidirectional messaging on the platform.
Approach / What changed
It deploys the flychat-ws example with flyctl, using an Express server and the ws library, a fly.toml service definition, and a Dockerfile that sets PORT=8080. The client chooses ws or wss based on the served protocol, while the server broadcasts incoming JSON messages to all connected clients.
Takeaways
fly.toml routes external HTTP traffic on port 80 and TLS/HTTP traffic on port 443 to the application’s internal TCP port 8080.
The WebSocket server uses its maintained client list to broadcast each incoming message to every connected client, including the sender.
TLS is terminated at Fly’s network edge, so the application handles traffic through its regular application port without special TLS connection code.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.