1

I'd like to set up a web server in my app which requires a forever loop. The waits in the loop allow the GUI to keep processing interface events.

But if I start the loop, then I can't exit from it to start the GUI.

And if I'm in the GUI already, then although I can use a button to get the user to start the web server, I'd like to do this automatically.

I tried in RebGUI attaching the web server code to a button and then:

start: button "Start" [ forever [ .. web server code ... ] ]

and later on start using

start/action/on-click start

but that doesn't work.

HappySpoon
  • 233
  • 2
  • 8

1 Answers1

2

Within the forever loop for the webserver you could start the gui when some condition occurs.

Or if you want to be in the GUI already, create a loop for your gui (which includes a short wait) break out and start the webserver loop when some condition occurs.

E.g:

REBOL [
    purpose: {Demonstrate breaking from one event loop to go to another.}
]

view/new layout [
    origin 0
    h1 400 rate 1 feel [
        engage: func [face act evt] [
            face/text: reform [now/time mode]
            show face
        ]
    ]
] 200x100

mode: "Initial Loop"
started: now
while [now < (started + 00:00:04)] [
    wait 0.1
]

mode: "Final Loop"
wait none
Brett
  • 428
  • 3
  • 11
  • Got some code to demonstrate how this would work when in eg. VID ? I can't take the GUI down. – Graham Chiu Jul 19 '14 at 04:53
  • Sorry, but this shows switching from one event handler to another, but does not show both running concurrently. – Graham Chiu Jul 19 '14 at 05:23
  • This is an example I wrote for Rebol3 https://github.com/gchiu/Rebol3/blob/master/scripts/gui-server.reb and I guess I have to write an async http server. – Graham Chiu Jul 19 '14 at 05:30
  • When the webserver loop is hit both the webserver and gui should be supported - concurrently. That's the job of WAIT. The question is tagged Rebol 2, my answer is too. I feel I've answered the question as written, perhaps the question needs rephrasing/rewriting and some code? – Brett Jul 19 '14 at 06:12
  • You can also check Cheyenne Web Server's embed mode, there is a nice sample GUI works with embeded web server: http://cheyenne-server.org/ – endo64 Jul 19 '14 at 17:26