Hi,
I'm trying to write a basic webserver in Gambit Scheme. However, my efforts are being stymied at the very beginning by the fact that I can't seem to even use the most basic procedures properly...can anyone help?
Here's what I'm trying to do now: (In REPL:)
Gambit Version 4.0 beta 21
(define s (open-tcp-server (list port-number: 8080 eol-encoding: 'cr-lf))) (define p (read s))
Then, I go to a browser (tried in both Opera and Firefox) http://localhost:8080
The browser goes to the page, and the `(read s)' stops blocking
Back at REPL:
(read-line p)
"GET / HTTP/1.1"
(display "content-type: text/plain\n" p) (display "Hello World!\n" p) (force-output p)
...And nothing happens...the page keeps trying to load, nothing is shown. What am I doing wrong? I tried looking at the code in the example webserver, but it didn't help much, since its much more complicated than what I'm trying to do here. Can anyone help?
Much obliged, James
Afficher les réponses par date
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 8-Mar-07, at 4:27 PM, James Cash wrote:
Back at REPL:
(read-line p)
"GET / HTTP/1.1"
(display "content-type: text/plain\n" p) (display "Hello World!\n" p) (force-output p)
...And nothing happens...the page keeps trying to load, nothing is shown. What am I doing wrong? I tried looking at the code in the example webserver, but it didn't help much, since its much more complicated than what I'm trying to do here. Can anyone help?
Did you try (close-port p) ?
Marc
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 8-Mar-07, at 4:57 PM, Marc Feeley wrote:
Did you try (close-port p) ?
Actually the fundamental problem is that you are not obeying the HTTP/ 1.1 protocol. You should do something like:
(define s (open-tcp-server (list port-number: 8080 eol-encoding: 'cr- lf))) (define p (read s)) (pp (read-line p)) (display "HTTP/1.1 200 OK\n" p) (display "Content-Length: 14\n" p) (display "Content-Type: text/plain\n" p) (display "\n" p) (display "Hello World!\n" p) (force-output p)
For completeness you should check the HTTP version on the first request line and act accordingly.
This is just friendly advice... I'm not an HTTP protocol expert.
Marc