<html><head><base href="x-msg://1140/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Here is a more Racket-y version of this: </div><div><br></div><div><div>#lang racket</div><div><br></div><div>(define (ping hostname port-no personalip)</div><div>  (define c (make-custodian))</div><div>  (define t</div><div>    (parameterize ((current-custodian c))</div><div>      (thread</div><div>       (lambda ()</div><div>         (with-handlers ((exn:fail:network? </div><div>                          (lambda (x)</div><div>                            (printf "~a:~a ~a\n" hostname port-no " NO"))))</div><div>           (define-values (in out) (tcp-connect hostname port-no))</div><div>           (write "'ping" out)</div><div>           (write personalip out)</div><div>           (flush-output out)</div><div>           (printf "~a:~a ~a\n" hostname port-no (read in)))))))</div><div>  (sync/timeout 0.01 t)</div><div>  (custodian-shutdown-all c))</div></div><div><br></div><div><br></div><div><br></div><br><div><div>On Apr 20, 2014, at 10:41 AM, nicolas carraggi wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="hmmessage" style="font-size: 12pt; font-family: Calibri; "><div dir="ltr">Hey guys,<div><br></div><div>Thanks a lot for your quick answers!</div><div><br></div><div>My ping method now:</div><div><br></div><div><div>(define (ping hostname port-no personalip)</div><div>  (define t (thread</div><div>             (lambda ()</div><div>               (with-handlers ((exn:fail:network? (lambda (x) (begin (displayln (string-append hostname ":" (number->string port-no) " NOOOOOOOOOO")) #f))));(displayln (exn-message x)))))</div><div>                 (define-values (in out) (tcp-connect hostname port-no))</div><div>                 (write "'ping" out)</div><div>                 (write personalip out)</div><div>                 (flush-output out)</div><div>                 (display (string-append hostname ":" (number->string port-no) " "))</div><div>                 (displayln (read in))</div><div>                 (close-input-port in)</div><div>                 (close-output-port out)</div><div>                 #t))))</div><div>  (sync/timeout 0.01 t)</div><div>  (kill-thread t))</div><div><br></div><div>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div><br></div><div>This is the result when I do a multicast from 192.168.1.0 to 192.168.1.200. ( a lot of these don't exist and that's why tcp-connect was taking ages to throw an error.) Those returning a NOOOOO are existing network nodes where no server is running. Pong is the answer from the <span style="font-size: 12pt; ">server running on my</span><span style="font-size: 12pt; "> laptop.</span></div><div><br></div><div><div>> (multicast-ping "192.168.1.100" 8080 0 200)</div><div>192.168.1.0:8080 NOOOOOOOOOO</div><div>192.168.1.105:8080 NOOOOOOOOOO</div><div>192.168.1.108:8080 pong</div><div>-------------------</div><div>Multicast finished!</div></div><div><br></div><div>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</div><div><br></div><div><br></div><div>It's still test-code but it's working fine now, maybe the timout time is too small but now it works well!</div><div><br></div><div>Greetings,</div><div>Nicolas</div><br><div><hr id="stopSpelling">Subject: Re: [racket-dev] Implementation question<br>From:<span class="Apple-converted-space"> </span><a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a><br>Date: Sat, 19 Apr 2014 09:25:27 -0400<br>CC:<span class="Apple-converted-space"> </span><a href="mailto:nicocarraggi@hotmail.com">nicocarraggi@hotmail.com</a>;<span class="Apple-converted-space"> </span><a href="mailto:dev@racket-lang.org">dev@racket-lang.org</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:laurent.orseau@gmail.com">laurent.orseau@gmail.com</a><br><br><div><br></div><div>Let me recommend events instead: </div><div><br></div><div><div>#lang racket</div><div><br></div><div>;; Nat -> Void </div><div>;; wait for t seconds before connecting to<span class="Apple-converted-space"> </span><a href="http://google.com" target="_blank">google.com</a>, then stop</div><div>(define (do-work t)</div><div>  (thread</div><div>   (lambda ()</div><div>     (with-handlers ((exn:fail:network? (lambda (x) (displayln (exn-message x)))))</div><div>       (sleep t)</div><div>       (define-values (in out) (tcp-connect "<a href="http://google.com" target="_blank">google.com</a>" 80)) </div><div>       'done))))</div><div><br></div><div>;; returns #f if 3 seconds pass w/o the thread shutting down </div><div>(sync/timeout 3 (do-work (random 6)))</div></div><div><br></div><div><br></div><br><div><div>On Apr 19, 2014, at 8:34 AM, Laurent wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div dir="ltr"><div><div>One simpler possibility is to use `tcp-connect/enable-break` and run a timer in parallel to break it after a shorter delay.<br></div>For example:<br><br>(define-values (in out) (values #f #f))<br><br>(define connect-thread<br>  (thread<br>   (λ()(set!-values (in out)<span class="Apple-converted-space"> </span><br>                    (tcp-connect "<a href="http://www.google.com/" target="_blank">www.google.com</a>" 80)))))<br><br>(sleep 3)<br>(unless in<br>  (displayln "Connection not established. Breaking thread.")<br>  (break-thread connect-thread))<br><br></div><div>The timer can also be place into its own thread if you need to set up several connections in parallel.<br><br></div><div>Hope this helps,</div>Laurent<br></div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Thu, Apr 17, 2014 at 6:48 PM, nicolas carraggi<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:nicocarraggi@hotmail.com" target="_blank">nicocarraggi@hotmail.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br><blockquote class="ecxgmail_quote" style="border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; "><div><div dir="ltr">Hello,<div><br></div><div>I am actually using "Racket/tcp" for a project in Racket.</div><div>I'm creating a peer-to-peer network but now I encountered a small problem.</div><div>For a multicast I want to connect with each server on the same network. </div><div>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.</div><div><br></div><div>Where can I find the implementation of "tcp-connect"?</div><div><br></div><div>I already found "tcp.rkt" but there it gets the "tcp-connect" method from "'#%network" but I can't find this one...</div><div><br></div><div>Greetings!</div><span class="ecxHOEnZb"><font color="#888888"><div>Nicolas</div></font></span></div></div><br>_________________________<br>  Racket Developers list:<br> <span class="Apple-converted-space"> </span><a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br><br></blockquote></div><br></div>_________________________<br> Racket Developers list:<br> <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br></blockquote></div><br></div></div></div></div><br class="Apple-interchange-newline"></blockquote></div><br></body></html>