[plt-scheme] How to execute eval from a network udp socket?

From: Todd Rovito (rovitotv at gmail.com)
Date: Tue Jun 30 05:14:59 EDT 2009

   I am new to scheme trying to learn.  Currently I have a closed
network where I am passing s-expressions around with UDP sockets.  The
UDP sockets work well in scheme now I need to go to the next level and
actually execute those s-expressions.  Here is an example server:

(define repl-buffer (make-bytes 1024 ))
(define sleep-secs 1)
(define port 51515)
(define the-socket (udp-open-socket))

(define (doit x x-max dx)
  (when (<= x x-max)
      (sleep sleep-secs)
      (printf "for loop:~a\n" x)
      (let-values (((n ip port)
                      (udp-receive!* the-socket repl-buffer)))
          (if n (printf "Received something:~a\n" repl-buffer) ; how
do I eval repl-buffer?
		(printf "No data read on udp socket\n") ) )
      (doit (+ x dx) x-max dx)

(define (start-tvr-test)
  (printf "Scheme UDP ServerREPL Version 2\n")
  (udp-bind! the-socket #f port)
  (doit 0 50 1) ; execute loop from 0 to 50 in steps of 1
  (udp-close the-socket)


I can then execute netcat to send udp s-expressions to the server like
so "nc -u 51515" then enter (+ 2 3) and I can see the
string in the repl-buffer.  Now my question is how do I execute the
repl-buffer to get the answer 5?  I would like to use the eval
function but I don't understand the arguments that I need.  Any help
would be greatly appreciated.  Thanks.

Posted on the users mailing list.