I’ve followed the docs which help with setting up a UDP service and deploying it given the provided github repo. Fortunately so far, everything looked fined and I was able to perform the test with netcat (echo "hello world" | nc -w1 -u *.fly.dev 5000
) and got “hello world” back. When I tried with my own coap server it wouldn’t be reachable by my client. I can’t seem to find out why.
I did bind on the fly-global-services
and also opt-in for a dedicated ipv4.
fly.toml
app = 'snitch-server'
primary_region = 'ams'
[[services]]
auto_start_machines = true
auto_stop_machines = true
internal_port = 5000
min_machines_running = 0
protocol = "udp"
[[services.ports]]
port = 5000
[[vm]]
cpu_kind = 'shared'
cpus = 1
memory = '1gb'
Dockerfile:
FROM golang:1.22-alpine as build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN go build -o coap-server ./cmd/coap-server
FROM alpine:latest
WORKDIR /app
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /app/coap-server /app
CMD [ "./coap-server" ]
go server:
func main() {
r := mux.NewRouter()
r.Handle("/a", mux.HandlerFunc(handleA))
r.Handle("/b", mux.HandlerFunc(handleB))
go func() {
log.Fatal(coap.ListenAndServe("udp", "fly-global-services:5000", r))
}()
log.Println("🫡 Listening for a coap message on port 5688")
select {}
}