initial socketpair test, same process pasted by zbigniew the sanguine on Sun Feb 12 00:25:23 2012

#;1> (define-values (i1 o1 i2 o2) (unix-pair))
#;41> (write-line "hello there" o1)
#;42> (read-line i2)
"hello there"
#;43> (write-line "foo" o2)
#;44> (read-line i1)
"foo"

IPC get pasted by zbigniew the sanguine on Sun Feb 12 00:39:47 2012

(use unix-sockets)
(use posix)

(define-values (ip op ic oc) (unix-pair))
(process-fork (lambda ()
                (let ((p (current-process-id))
                      (r (read-line ic)))
                  (print "pid " p " read: " r)
                  (let ((w (number->string (+ 1 (string->number r)))))
                    (print "pid " p " write: " w)
                    (write-line w oc)
                    (flush-output oc)
                    (print (read-line ic))))))

(let ((p (current-process-id))
      (w (number->string (random 33))))
  (print "pid " p " write: " w)
  (write-line w op)
  (let ((r (read-line ip)))
    (print "pid " p " read: " r)
    (write-line "bye" op)
    (flush-output op)))

#|
Example output:

jim@aeryn ~/scheme/chicken-eggs4/unix-sockets/trunk$ csi -script socketpair-test.scm
pid 4411 write: 20
pid 4412 read: 20
pid 4412 write: 21
pid 4411 read: 21
bye
|#

read/write instead of read-line/write-line added by zbigniew the sanguine on Sun Feb 12 01:39:33 2012

The below also works, where we write and read sexprs instead of lines.  However, symbols and numbers must explicitly be terminated, for example by whitespace or ), as the ports are streams.

diff --git a/socketpair-test.scm b/socketpair-test.scm
--- a/socketpair-test.scm
+++ b/socketpair-test.scm
@@ -4,19 +4,19 @@
 (define-values (ip op ic oc) (unix-pair))
 (process-fork (lambda ()
                 (let ((p (current-process-id))
-                      (r (read-line ic)))
+                      (r (read ic)))
                   (print "pid " p " read: " r)
-                  (let ((w (number->string (+ 1 (string->number r)))))
+                  (let ((w (+ 1 r)))
                     (print "pid " p " write: " w)
-                    (write-line w oc)
+                    (write w oc) (newline oc)
                     (flush-output oc)
-                    (print (read-line ic))))))
+                    (print (read ic))))))
 
 (let ((p (current-process-id))
-      (w (number->string (random 33))))
+      (w (random 33)))
   (print "pid " p " write: " w)
-  (write-line w op)
-  (let ((r (read-line ip)))
+  (write w op) (newline op)
+  (let ((r (read ip)))
     (print "pid " p " read: " r)
     (write-line "bye" op)
     (flush-output op)))