First, an example of socket:
1: (module socket)
2:
3: (let ((s (make-server-socket)))
4: (dynamic-wind
5: ;; Init: Launch an xterm with telnet running
6: ;; on the s listening port and connect
7: (lambda ()
8: (run-process "xterm" "-e" "telnet" "localhost"
9: (number->string (socket-port-number s))))
10:
11: ;; Action: A toplevel like loop
12: (lambda ()
13: (let ((c (socket-accept s)))
14: (display #"\nWelcome on the socket REPL.\n\n> " (socket-output c))
15: (flush-output-port (socket-output c))
16: (let loop ()
17: (fprint (socket-output c)
18: "; Result: "
19: (eval (read (socket-input c))))
20: (display "> " (socket-output c))
21: (flush-output-port (socket-output c))
22: (loop))))
23:
24: ;; Termination: We go here when
25: ;; -a: an error occurs
26: ;; -b: connection is closed
27: (lambda ()
28: (print #"Shutdown ......\n")
29: (socket-shutdown s))))
|
|
Then, an example of processes:
1: (module process-example
2: (main main))
3:
4: (define (main argv)
5: (print "running: ./a-proc" argv)
6: (let* ((proc (apply run-process "./a-proc"
7: env: "FOO=0" env: "BAR=1" env: "GEE=2"
8: error: pipe: output: pipe: argv))
9: (out (process-output-port proc))
10: (err (process-error-port proc)))
11: (purge err)
12: (purge out)))
13:
14: (define (purge port)
15: (let loop ((line (read-line port)))
16: (if (eof-object? line)
17: (close-input-port port)
18: (begin
19: (print line)
20: (loop (read-line port))))))
|
|