[racket-dev] Implementation question
Let me recommend events instead:
#lang racket
;; Nat -> Void
;; wait for t seconds before connecting to google.com, then stop
(define (do-work t)
(thread
(lambda ()
(with-handlers ((exn:fail:network? (lambda (x) (displayln (exn-message x)))))
(sleep t)
(define-values (in out) (tcp-connect "google.com" 80))
'done))))
;; returns #f if 3 seconds pass w/o the thread shutting down
(sync/timeout 3 (do-work (random 6)))
On Apr 19, 2014, at 8:34 AM, Laurent wrote:
> One simpler possibility is to use `tcp-connect/enable-break` and run a timer in parallel to break it after a shorter delay.
> For example:
>
> (define-values (in out) (values #f #f))
>
> (define connect-thread
> (thread
> (λ()(set!-values (in out)
> (tcp-connect "www.google.com" 80)))))
>
> (sleep 3)
> (unless in
> (displayln "Connection not established. Breaking thread.")
> (break-thread connect-thread))
>
> The timer can also be place into its own thread if you need to set up several connections in parallel.
>
> Hope this helps,
> Laurent
>
>
> On Thu, Apr 17, 2014 at 6:48 PM, nicolas carraggi <nicocarraggi at hotmail.com> wrote:
> Hello,
>
> I am actually using "Racket/tcp" for a project in Racket.
> I'm creating a peer-to-peer network but now I encountered a small problem.
> For a multicast I want to connect with each server on the same network.
> For this I use "tcp-connect", but when i try to connect to an ip address which is not hosting a server, throwing the error only happens after more than 1 minute. So I would like to use a modified "tcp-connect" with a smaller time-out.
>
> Where can I find the implementation of "tcp-connect"?
>
> I already found "tcp.rkt" but there it gets the "tcp-connect" method from "'#%network" but I can't find this one...
>
> Greetings!
> Nicolas
>
> _________________________
> Racket Developers list:
> http://lists.racket-lang.org/dev
>
>
> _________________________
> Racket Developers list:
> http://lists.racket-lang.org/dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20140419/4ab398d6/attachment.html>