[gambit-list] open-tcp-client problem?

Francois Magnan magnan at licef.teluq.uquebec.ca
Mon Aug 8 15:22:44 EDT 2005


Hi,

I have some difficulties using the open-tcp-client primitive on  
MacOSX 10.4 with Gambit-Cb14. The primitive returns a port before  
that port is actually ready to be used for sending/receiving data.  
See below for an example (Use two separate hosts to reproduce the  
error... don't try this with the client and server running on the  
same host).

If the client (host B) is MacOSX 10.4 the second call to (do-call)  
fails.

Any hints?
Thank you,

Francois Magnan


-------------------

;;;
;;;; --
;;;; simple server
;;;

; Run this on host A


(define (server-start)
   (let ((command-queue (open-tcp-server
                             (list port-number: 5000
                                   reuse-address: #t
                                   eol-encoding: 'cr))))
     (let loop ()
       (let ((incoming-connection (read command-queue)))
         (display "Got connection\n")
         (serve-command incoming-connection))
       (loop))))


(define (serve-command incoming-connection)
   (let* ((parsed-command (read incoming-connection)))
     (display (list "received command" parsed-command))
     (if parsed-command
         (write "toto" incoming-connection))
     (close-port incoming-connection)))


(thread-start! (make-thread (lambda ()
                               (server-start))))



-------------------


;;;
;;;; --
;;;; simple client
;;;

; run this on host B


(define Host-A-IP "206.167.88.52")

(define (do-call sleep?)
   (let* ((connection (open-tcp-client (list server-address: Host-A- 
IP ; put Host A IP here
                                             port-number: 5000
                                             eol-encoding: 'cr))))
     (if sleep?
         (thread-sleep! 1))
     (write (list 1 2 3) connection)
     (display "\n" connection)
     (force-output connection)
     (let ((result (read connection)))
       (close-port connection)
       result)))


(define (test)
   (thread-sleep! 1)
   (display "try with sleeping...\n")
   (do-call #t)
   (display "sleeping...\n")
   (force-output)
   (thread-sleep! 1)
   (display "now try without sleeping...\n")
   (do-call #f))


;(##repl)
(test)

; Fails on MacOSX 10.4
; Works on Windows XP (MinGW)

-------------------



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20050808/67a6a253/attachment-0001.html


More information about the Gambit-list mailing list