diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:04:37 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:04:37 -0800 |
commit | 2a4088119cf41175457414dfa59bd4064b8f0562 (patch) | |
tree | 64fe184e399f9870ebd481a90eec34d51e5dff68 /archive/1.vm/http-server.mu | |
parent | 23fd294d85959c6b476bcdc35ed6ad508cc99b8f (diff) | |
download | mu-2a4088119cf41175457414dfa59bd4064b8f0562.tar.gz |
5852
Diffstat (limited to 'archive/1.vm/http-server.mu')
-rw-r--r-- | archive/1.vm/http-server.mu | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/archive/1.vm/http-server.mu b/archive/1.vm/http-server.mu new file mode 100644 index 00000000..6bd172b3 --- /dev/null +++ b/archive/1.vm/http-server.mu @@ -0,0 +1,28 @@ +# 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 +# +# After running it, navigate to localhost:8080. Your browser should display +# "SUCCESS!" and the server will terminate after one connection. + +def main [ + local-scope + socket:num <- $open-server-socket 8080/port + $print [Mu socket creation returned ], socket, 10/newline + return-unless socket + session:num <- $accept socket + contents:&:source:char, sink:&:sink:char <- new-channel 30 + sink <- start-running receive-from-socket session, sink + 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! +] + $print 10/newline, [Wrote to and closing socket...], 10/newline + session <- $close-socket session + socket <- $close-socket socket +] |