; httpdemo.vnm ; short demo of http server ; (A) 2014-07-27 changed to use embedded text in send_response procedure ; Minimal Web server serving pages created on the fly ; (i.e. not from a local file system) ; IP addresses: ; The VM2 obtains its IP address from a DHCP server on your LAN. ; This IP address is not guaranteed to stay the same from run to run. ; For real applications you may need to configure the DHCP server on your ; LAN to allocate a fixed IP address to the VM2. To init Make eth Ethernet Make http HTTPServer Make s String(100) Make t Stopwatch ; to generate some timing info for display counter := 0 End ; processes incoming HTTP requests To main eth.Connect Print "http server running; IP address ", eth:2, CR t.Reset Forever [ http.Get(s) ; wait for a request Print "received request: ", s, CR If s.Compare("/") = 0 ; we only service requests for "/" [ counter := counter + 1 send_response ] http.Flush ; ] End ; response to root "GET /" request To send_response http.printf(<<VM2 HTTP demo Hello.
Your IP address is %I
%u milliseconds have elapsed since last request
this page has been displayed %u times
>>>, http.Address, t.Time, counter) t.Reset End