September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,47 @@
' Define HTTP constants
CONST New$ = CHR$(13) & NL$
CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$
CONST Msg$ = "<html><head>BaCon web greeting</head><body><h2>Goodbye, World!</h2></body></html>"
' Get our IP
Ip$ = "localhost"
PRINT "Connect from browser '", Ip$, ":8080'."
' Ignore child signals to avoid zombie processes
SIGNAL SIG_IGN, SIGCHLD
' Keep receiving requests
WHILE TRUE
' Open listening port
OPEN Ip$ & ":8080" FOR SERVER AS mynet
' Incoming connection -> create background process
spawn = FORK
' We are in the child
IF spawn = 0 THEN
' Get the request
REPEAT
RECEIVE dat$ FROM mynet
PRINT dat$
UNTIL RIGHT$(dat$, 4) = Sep$
' Reply that we're OK
SEND "HTTP/1.1 200 Ok" & New$ & "Content-Length: " & STR$(LEN(Msg$)) & Sep$ & Msg$ TO mynet
' Close connection
CLOSE SERVER mynet
' End this process
END
' We are in the parent
ELIF spawn > 0 THEN
' Close connection in parent
CLOSE SERVER mynet
ENDIF
WEND