Skip to content
Browse files

Update README to show how to run a basic webserver

  • Loading branch information...
1 parent e9ec302 commit ec2a227b61d6463645a1ff4b2d7471193b8a5379 @davidreynolds committed Aug 21, 2010
Showing with 14 additions and 9 deletions.
  1. +9 −6 README
  2. +5 −3 examples/webserver/webserver.scm
View
15 README
@@ -10,22 +10,25 @@ Run make to generate rooster.so
$ make
-To use rooster.so:
+To use rooster.so for a basic web server:
(require 'rooster)
- (define (handler fd rbuf)
- ;; echo input back to client
- (send-to-client fd rbuf))
+ (define (handler fd buf)
+ (let* ((msg "Hello, world")
+ (headers (format
+ "HTTP/1.1 200 OK\r\nContent-Length:~A\r\n\r\n"
+ (string-length msg))))
+ (send-to-client fd (string-append headers msg))))
;; pass handler to rooster
(run-rooster handler)
To run the examples, make rooster and then do:
- $ csi examples/echo/echo.scm
+ $ csi examples/webserver/webserver.scm
You'll then be dropped into the Chicken Scheme Interpreter and from another shell prompt
you can
- $ telnet localhost 6666
+ $ curl localhost:6666
View
8 examples/webserver/webserver.scm
@@ -1,8 +1,10 @@
(require 'rooster)
-(define headers "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\n")
-
(define (handler fd buf)
- (send-to-client fd (string-append headers "Hello, world")))
+ (let* ((msg "Hello, world")
+ (headers (format
+ "HTTP/1.1 200 OK\r\nContent-Length:~A\r\n\r\n"
+ (string-length msg))))
+ (send-to-client fd (string-append headers msg))))
(run-rooster handler)

0 comments on commit ec2a227

Please sign in to comment.
Something went wrong with that request. Please try again.