Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
45
Task/Hello-world-Web-server/Phix/hello-world-web-server.phix
Normal file
45
Task/Hello-world-Web-server/Phix/hello-world-web-server.phix
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
-- demo\rosetta\SimpleHttpServer.exw
|
||||
include builtins\sockets.e -- added for 0.8.1 (not yet documented)
|
||||
|
||||
constant MAX_QUEUE = 100,
|
||||
ESCAPE = #1B,
|
||||
BUFFER_SIZE = 2048,
|
||||
buffer = allocate(BUFFER_SIZE),
|
||||
sock_addr = new_sock_addr(AF_INET, 8080, NULL),
|
||||
peerAddr = new_sock_addr(),
|
||||
|
||||
response = substitute("""
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bye-bye baby bye-bye</title>
|
||||
<style>
|
||||
body { background-color: #111 }
|
||||
h1 { font-size:4cm; text-align: center; color: black;
|
||||
text-shadow: 0 0 2mm red}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Goodbye, world!</h1>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
""","\n","\r\n")
|
||||
|
||||
atom sock = socket(AF_INET,SOCK_STREAM,NULL)
|
||||
bind(sock,sock_addr)
|
||||
listen(sock,MAX_QUEUE)
|
||||
while get_key()!=ESCAPE do
|
||||
atom peer = accept(sock,peerAddr),
|
||||
ip = get_sin_addr(sock_addr)
|
||||
integer len = recv(peer,buffer,BUFFER_SIZE,0)
|
||||
string request = peek({buffer,len})
|
||||
printf(1,"Client IP: %s\n%s\n",{ip_to_string(ip),request})
|
||||
if length(request)>3 and request[1..4]="GET " then
|
||||
poke(buffer,response)
|
||||
send(peer,buffer,length(response),0)
|
||||
end if
|
||||
end while
|
||||
11
Task/Hello-world-Web-server/Pike/hello-world-web-server.pike
Normal file
11
Task/Hello-world-Web-server/Pike/hello-world-web-server.pike
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
void handle_request(Protocols.HTTP.Server.Request request)
|
||||
{
|
||||
request->response_and_finish( ([ "data":"Goodbye, World!",
|
||||
"type":"text/html" ]) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Protocols.HTTP.Server.Port(handle_request, 8080);
|
||||
return -1; // -1 is a special case that retirns control to the backend
|
||||
}
|
||||
9
Task/Hello-world-Web-server/R/hello-world-web-server.r
Normal file
9
Task/Hello-world-Web-server/R/hello-world-web-server.r
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
library(httpuv)
|
||||
|
||||
runServer("0.0.0.0", 5000,
|
||||
list(
|
||||
call = function(req) {
|
||||
list(status = 200L, headers = list('Content-Type' = 'text/html'), body = "Hello world!")
|
||||
}
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue