Racket REPL over TCP
I've built a rather complex application with Racket (formerly PLT Scheme) and would like to add a REPL for debugging purposes. I've tried to make it accessible over a TCP stream:

    (define repl-server
      (thread (lambda ()
              (let ((listener (tcp-listen 8082 5 #t)))
                (do () (#f)
                  (let-values (((in out) (tcp-accept listener)))
                    (thread (lambda ()
                              (let ((port-string (get-port-string in)))
                                 (Try "debug-repl" #f
                                   (begin
                                     (file-stream-buffer-mode out 'line)
                                     (display-and-log "Password: " out)
                                     (flush-output out)
                                     (when (string=? (read-line in) "whatever")
                                       (log "Connect to REPL: " port-string))
                                       (current-input-port in)
                                       (current-output-port out)
                                       (current-error-port out)
                                       (read-eval-print-loop))
                                     (close-input-port in)
                                     (close-output-port out))))))))))))

`(Try name result-if-exception form)` is a macro providing basic exception handling, (log ...) and (display-and-log ...) do what they sound like.

Now if I access the REPL, I can't even evaluate constants, as I keep getting the error `compile: unbound identifier (and no #%app syntax transformer is bound) at: #%top-interaction`. How can I make this REPL work? And how can I access values `define`d before starting the REPL server?
Racket REPL over TCP
===

I've built a rather complex application with Racket (formerly PLT Scheme) and would like to add a REPL for debugging purposes. I've tried to make it accessible over a TCP stream:

    (define repl-server
      (thread (lambda ()
              (let ((listener (tcp-listen 8082 5 #t)))
                (do () (#f)
                  (let-values (((in out) (tcp-accept listener)))
                    (thread (lambda ()
                              (let ((port-string (get-port-string in)))
                                 (Try "debug-repl" #f
                                   (begin
                                     (file-stream-buffer-mode out 'line)
                                     (display-and-log "Password: " out)
                                     (flush-output out)
                                     (when (string=? (read-line in) "whatever")
                                       (log "Connect to REPL: " port-string))
                                       (current-input-port in)
                                       (current-output-port out)
                                       (current-error-port out)
                                       (read-eval-print-loop))
                                     (close-input-port in)
                                     (close-output-port out))))))))))))

`(Try name result-if-exception form)` is a macro providing basic exception handling, (log ...) and (display-and-log ...) do what they sound like.

Now if I access the REPL, I can't even evaluate constants, as I keep getting the error `compile: unbound identifier (and no #%app syntax transformer is bound) at: #%top-interaction`. How can I make this REPL work? And how can I access values `define`d before starting the REPL server?