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

From: Richard Cleis (rcleis at mac.com)
Date: Wed Jul 1 00:27:52 EDT 2009

Why is it so evil to depend on the top level name space, especially  
for launching things like servers?  This module works fine with netcat  
(although I would include exception handlers etc if I knew the goal of  

#lang scheme

(module  evil-eval-module scheme
  (provide make-evil-server)

  (require scheme/udp)

  (define (make-evil-server port buff-size)
    (define  byte-buff (make-bytes buff-size))
    (define  the-socket (udp-open-socket))
    (define  evil-eval-thread #f)

    (define (evil-evaler)
      (let-values (((n ipa port)
                    (udp-receive! the-socket byte-buff)))
        (when n
          (let  ((oob  (open-output-bytes)))
            (write (eval (read (open-input-bytes byte-buff))) oob)
            (write-byte 10 oob)
            (udp-send-to the-socket ipa port (get-output-bytes oob))))

    (lambda  (flag)
      (cond  ((equal? flag 'go)
              (udp-bind! the-socket #f port)
              (set! evil-eval-thread (thread evil-evaler)))
              (kill-thread evil-eval-thread)
              (udp-close the-socket)))))

The executive file contains:

(require "evil-eval-module.ss")

(define serve-evil-1 (make-evil-server 11111 1024))
(define serve-evil-2 (make-evil-server 22222 1024))

and the evil hacker starts them with:

(serve-evil-1 'go)
(serve-evil-2 'go)


On Jun 30, 2009, at 8:22 AM, Grant Rettke wrote:

> Hi Todd,
> On Tue, Jun 30, 2009 at 4:14 AM, Todd Rovito<rovitotv at gmail.com>  
> wrote:
>>  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:
> Here are some links that I have collected regarding this topic:
> http://download.plt-scheme.org/doc/html/reference/syntax-model.html#(part._namespace-model)
> http://download.plt-scheme.org/doc/html/reference/Namespaces.html
> http://download.plt-scheme.org/doc/html/reference/Sandboxed_Evaluation.html
> http://schemecookbook.org/Cookbook/DynamicEvalCustomNamespace
> http://schemecookbook.org/Cookbook/DynamicUntrustedEval
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.