Getting the port number of serve/servlet when running on an ephemeral port

The second case exists because the server might fail to start, in which case the channel will get an exception value instead of a port number. Here's an example of a program that will produce such an exception (as long as you run it with normal privileges):

#lang racket
(require web-server/web-server
         racket/async-channel)

(define ach
  (make-async-channel))
(define stop
  (serve #:confirmation-channel ach
         #:port 80 ;<-- needs privileges
         #:dispatch void))
(begin0 (sync ach)
  (sleep 1)
  (stop))
1 Like