about summary refs log tree commit diff stats
path: root/030container.cc
Commit message (Expand)AuthorAgeFilesLines
* 1276 - make C++ version the defaultKartik K. Agaram2015-05-051-0/+169
02 -0700 3403' href='/akkartik/mu/commit/server-socket.mu?h=hlt&id=25cd8e9878b7b7325271773d4e4ec91b7462d0e6'>25cd8e98 ^
3d91759b ^


68578a78 ^

a7c59e3e ^
68578a78 ^
29fe558a ^
192d59d3 ^
4543a0dd ^
f03c9c05 ^
433a7c7b ^
25cd8e98 ^




801e8b50 ^
25cd8e98 ^
215e35e4 ^

68578a78 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
]