thread input/output to port
Sorry for dumb question -- I have a tcp port. I'm starting a thread. How can I redirect all input/output from/to the thread to this tcp port? somethign like (let ((p (pre existing code that makes bidirectional port)) .. modify the following ... (thread-start! (make-thread func))) thanks!
Afficher les réponses par date
Got it working. Thanks! One question -- why is it that with printing to stdin, I don't need to use (force-output), whereas after I redirect to tcp ports, I seem to have to use (force-output) even after (newline) ? Thanks! On Tue, Oct 13, 2009 at 5:55 PM, Christian Jaeger <chrjae@gmail.com> wrote:
http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Sp... http://srfi.schemers.org/srfi-39/srfi-39.html
Christian.
On 2009-10-14, at 3:32 PM, lowly coder wrote:
Got it working. Thanks!
One question -- why is it that with printing to stdin, I don't need to use (force-output), whereas after I redirect to tcp ports, I seem to have to use (force-output) even after (newline) ?
Thanks!
That's because the default buffering mode for stdout is #f (no buffering). For tcp ports the default buffering is #t (fully buffered). You can change it like this: (open-tcp-server (list port-number: 22222 buffering: 'line)) to get "line buffering", or use #f for no buffering (this may be really slow as each character is sent individually). Marc
On 2009-10-13, at 8:00 PM, lowly coder wrote:
Sorry for dumb question --
I have a tcp port. I'm starting a thread. How can I redirect all input/output from/to the thread to this tcp port?
somethign like
(let ((p (pre existing code that makes bidirectional port)) .. modify the following ... (thread-start! (make-thread func)))
Here are three ways to do this. Marc (define (server1) (tcp-service-register! 11111 (lambda () (display "Hello\n")))) (define (server2) (let ((s (open-tcp-server 22222))) (let loop () (let ((connection (read s))) (thread-start! (make-root-thread (lambda () (display "World\n") ;; will go to "connection" (close-input-port (current-input-port)) (close-output-port (current-output-port))) 'hello (thread-thread-group (current-thread)) connection connection))) (loop)))) (define (server3) (let ((s (open-tcp-server 33333))) (let loop () (let ((connection (read s))) (parameterize ((current-input-port connection) (current-output-port connection)) (thread-start! (make-thread (lambda () (display "Bonjour\n") ;; will go to "connection" (close-input-port (current-input-port)) (close-output-port (current-output-port))) 'hello)))) (loop)))) (server1) (thread-start! (make-thread server2)) (server3)
participants (3)
-
Christian Jaeger -
lowly coder -
Marc Feeley