Hello world/Web server: Difference between revisions
Content added Content deleted
m (Fixed capitalization) |
|||
Line 154: | Line 154: | ||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
Requires BaCon 4.2 or higher. |
|||
<lang |
<lang bacon>' Define HTTP constants |
||
CONST New$ = CHR$(13) & NL$ |
CONST New$ = CHR$(13) & NL$ |
||
CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$ |
CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$ |
||
Line 165: | Line 166: | ||
' Ignore child signals to avoid zombie processes |
' Ignore child signals to avoid zombie processes |
||
SIGNAL SIG_IGN, SIGCHLD |
SIGNAL SIG_IGN, SIGCHLD |
||
⚫ | |||
OPEN Ip$ & ":8080" FOR SERVER AS mynet |
|||
' Keep receiving requests |
' Keep receiving requests |
||
WHILE TRUE |
WHILE TRUE |
||
' Handle for newly incoming connection |
|||
⚫ | |||
fd = ACCEPT(mynet) |
|||
' Incoming connection -> create background process |
' Incoming connection -> create background process |
||
Line 180: | Line 184: | ||
' Get the request |
' Get the request |
||
REPEAT |
REPEAT |
||
RECEIVE dat$ FROM |
RECEIVE dat$ FROM fd |
||
PRINT dat$ |
PRINT dat$ |
||
UNTIL RIGHT$(dat$, 4) = Sep$ |
UNTIL RIGHT$(dat$, 4) = Sep$ |
||
' Reply that we're OK |
' Reply that we're OK |
||
SEND "HTTP/1.1 200 Ok" & New$ & "Content-Length: " & STR$(LEN(Msg$)) & Sep$ & Msg$ TO |
SEND "HTTP/1.1 200 Ok" & New$ & "Content-Length: " & STR$(LEN(Msg$)) & Sep$ & Msg$ TO fd |
||
' Close connection |
' Close connection |
||
Line 191: | Line 195: | ||
' End this process |
' End this process |
||
ENDFORK |
|||
' We are in the parent |
|||
ELIF spawn > 0 THEN |
|||
' Close connection in parent |
|||
CLOSE SERVER mynet |
|||
ENDIF |
ENDIF |
||
WEND |
WEND</lang> |
||
</lang> |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |