Last active
August 29, 2015 14:18
-
-
Save DTSCode/9952b3b975672926003a to your computer and use it in GitHub Desktop.
Racketball - A webserver written in racket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (serve port-no) | |
(define listener | |
(tcp-listen port-no 5 #t)) | |
(define (loop) | |
(accept-and-handle listener) | |
(loop)) | |
(loop)) | |
(define (accept-and-handle listener) | |
(define-values (in out) (tcp-accept listener)) | |
(handle in out) | |
(close-input-port in) | |
(close-output-port out)) | |
(define (handle in out) | |
(regexp-match #rx"(\r\n|^)\r\n" in) | |
(display "HTTP/1.0 200 Okay\r\n" out) | |
(display "Server: k\r\nContent-Type: text/html\r\n\r\n" out) | |
(display "<html><body>Hello, world!</body></html>" out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment