[racket] Prevent racket From Closing
In your initial sample, add a \n at the end of the fprintf or add
(flush-output) at the end of start-server to get the message displayed.
On Mon, 12 Nov 2012 15:19:50 +0100, Nathan Campos
<nathanpc at dreamintech.net> wrote:
> Both ways worked, but the problem is that it's still blocking my script
> to
> display things on the command-line. When I Ctrl+C to terminate the
> execution I get the usual "user break" message and all the things I tried
> to display on the command-line.
>
>
> On Mon, Nov 12, 2012 at 12:00 PM, Greg Hendershott <
> greghendershott at gmail.com> wrote:
>
>> > When I try to use do-not-return I get this error: bonsai.rkt:22:3:
>> > do-not-return: unbound identifier in module
>>
>> To use it, you would need to require the module that provides it:
>>
>> (require web-server/web-server)
>>
>> (Which I found by searching the docs for `do-not-return', and getting
>> this:
>>
>> http://docs.racket-lang.org/web-server-internal/web-server.html#(def._((lib._web-server/web-server..rkt)._do-not-return))
>> )
>>
>> > Then I tried read-line, which worked, but it blocks the console
>> output so
>> > I'll only see the things that my script is sending to the console
>> after I
>> > hit Enter and finish the program. Is there a asynchronous way of doing
>> this?
>>
>> It sounds like you should use `do-not-return' as Jay recommended.
>>
>> If you don't want to require all of web-server to get it, the
>> definition is simply this:
>>
>> (define (do-not-return)
>> (semaphore-wait (make-semaphore 0)))
>>
>>
>> On Mon, Nov 12, 2012 at 8:42 AM, Nathan Campos
>> <nathanpc at dreamintech.net>
>> wrote:
>> > When I try to use do-not-return I get this error: bonsai.rkt:22:3:
>> > do-not-return: unbound identifier in module
>> >
>> > Then I tried read-line, which worked, but it blocks the console
>> output so
>> > I'll only see the things that my script is sending to the console
>> after I
>> > hit Enter and finish the program. Is there a asynchronous way of doing
>> this?
>> >
>> >
>> >
>> > On Mon, Nov 12, 2012 at 1:55 AM, Greg Hendershott
>> > <greghendershott at gmail.com> wrote:
>> >>
>> >> If I understand correctly you simply need your main Racket thread to
>> >> wait, for example, after your main thread calls your `start-server':
>> >>
>> >> (start-server)
>> >> (displayln "Server started. Press ENTER to quit.")
>> >> (read-line)
>> >> ;; End of your main RKT file
>> >>
>> >>
>> >> On Sun, Nov 11, 2012 at 8:39 PM, Nathan Campos <
>> nathanpc at dreamintech.net>
>> >> wrote:
>> >> > I'm having some fun with tcp-listen with Racket, here's the simple
>> start
>> >> > server function that I'm using:
>> >> >
>> >> > #lang racket
>> >> >
>> >> > (define start-server
>> >> > (lambda ([port 8080])
>> >> > (current-custodian server-custodian)
>> >> > ; Caps at 50 connections at the same time
>> >> > (define listener (tcp-listen port 50 #t))
>> >> > (define (loop)
>> >> > (accept-and-handle listener)
>> >> > (loop))
>> >> > (define t (thread loop))
>> >> > (lambda ()
>> >> > (kill-thread t)
>> >> > (tcp-close listener))
>> >> > (fprintf (current-output-port) "Server started listening at ~a"
>> >> > port)))
>> >> >
>> >> > It was running great on DrRacket, but when I tried to run it under
>> >> > racket
>> >> > (the command-line executable) it shows the sever started message
>> and
>> >> > quits,
>> >> > so the server doesn't keep running. Is there anyway to make racket
>> wait
>> >> > until it's process gets killed or the user types something?
>> >> >
>> >> > Best Regards,
>> >> > Nathan Campos
>> >> >
>> >> > ____________________
>> >> > Racket Users list:
>> >> > http://lists.racket-lang.org/users
>> >> >
>> >
>> >
>> >
>> > ____________________
>> > Racket Users list:
>> > http://lists.racket-lang.org/users
>> >
>>
--
---------------------------------------------------------
Tobias Hammer
DLR / Institute of Robotics and Mechatronics
Muenchner Str. 20, D-82234 Wessling
Tel.: 08153/28-1487
Mail: tobias.hammer at dlr.de