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)
-------------------
Afficher les réponses par date
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.
Is this a problem? The Gambit runtime performs an asynchronous connect. This is done so that multiple connections can be started in parallel. If there is a connection error it will be reported the next time you do I/O on that port.
Marc
Hi,
Ok, this is a nice feature but it could be implemented by the programmer using threads . If I want a sequential behavior I will have to loop by catching connections errors until the connection is completed. The loop will also have to distinguish between real connection errors and "still not connected" errors. This is a little odd to me but I can write such a function.
Thanks, Francois Magnan
On 05-08-09, at 09:13, feeley@iro.umontreal.ca wrote:
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.
Is this a problem? The Gambit runtime performs an asynchronous connect. This is done so that multiple connections can be started in parallel. If there is a connection error it will be reported the next time you do I/O on that port.
Marc
You are right... open-tcp-client should block the thread until the connection is established. What is important is to not block the Scheme process, so that other threads can progress. I will change this for the next release.
Marc
On 9-Aug-05, at 9:24 AM, Francois Magnan wrote:
Hi,
Ok, this is a nice feature but it could be implemented by the programmer using threads . If I want a sequential behavior I will have to loop by catching connections errors until the connection is completed. The loop will also have to distinguish between real connection errors and "still not connected" errors. This is a little odd to me but I can write such a function.