Faried Nawaz | 28 Jun 2003 03:41

threaded socket code.


Hello,

I'm trying to write a simple socket client using threads in scheme48, and
I'm stuck. My code connects to the server, and spawns a thread to handle
incoming server messages. I end up back at the toplevel where I can type
(send-line "foo") and send stuff to other end.

The thread that waits for server messaegs just sits there, doing nothing. I
can't figure out why.

The ugly code is at http://web.nilpotent.org/tmp/sock-thread.scm

Faried.
--

-- 
The Great GNU has arrived, infidels, behold his wrath !
"If a MOO runs on a port no one accesses, does it run?"

Richard Kelsey | 28 Jun 2003 21:37
Favicon

Re: threaded socket code.

Scheme48 threads do not inherit the dynamic environment of the
SPAWN call that creates them.  Something like

  (define (echo-client)
    (let ((server "localhost")
          (port 50007))
      (call-with-values
       (lambda () (socket-client server port))
       (lambda (read-port write-port)
         (display "connected!") (newline)
         (spawn (lambda ()
                  (let-fluid! *write-port* write-port
                    (lambda ()
                      (call-with-current-input-port read-port
                        handle-server-input))))
	        'server-input)))))

should work, although I would suggest passing READ-PORT and
WRITE-PORT to HANDLE-SERVER-INPUT directly instead of using
fluids.
                                    -Richard Kelsey


Gmane