mu/http-server.mu

29 lines
972 B
Plaintext
Raw Normal View History

2016-10-08 17:12:44 +00:00
# example program: a single-request HTTP server
# listen for connections from clients on a server socket
# when a connection occurs, transfer it to a session socket
# read from it using channels
# write to it directly
#
2016-10-08 17:12:44 +00:00
# After running it, navigate to localhost:8080. Your browser should display
# "SUCCESS!" and the server will terminate after one connection.
def main [
local-scope
2016-10-08 03:11:47 +00:00
socket:num <- $open-server-socket 8080/port
$print [Mu socket creation returned ], socket, 10/newline
2016-10-07 17:36:04 +00:00
return-unless socket
session:num <- $accept socket
2016-09-22 07:40:59 +00:00
contents:&:source:char, sink:&:sink:char <- new-channel 30
2016-10-16 18:11:54 +00:00
sink <- start-running receive-from-socket session, sink
2016-10-21 00:14:37 +00:00
query:text <- drain contents
$print [Done reading from socket.], 10/newline
write-to-socket session, [HTTP/1.0 200 OK
Content-type: text/plain
SUCCESS!
2016-10-08 17:14:32 +00:00
]
$print 10/newline, [Wrote to and closing socket...], 10/newline
2016-10-25 19:39:43 +00:00
session <- $close-socket session
socket <- $close-socket socket
]