[Ecls-list] why doesn't my stupid mini http-server run?

fBechmann at t-online.de fBechmann at t-online.de
Wed Nov 9 22:55:00 UTC 2005


... I already tried a CRLF version w/

===
    "~A ~D 
~A~C~C~C~C<html><head><title>foo</title></head><body>bar!</body></html>~%"
    "HTTP/1.0" 200 "OK" #\Return #\Linefeed #\Return #\Linefeed
===

but that didn't work either.
what's even worse: when I got it running later (see below), that didn't 
work w/ IE
(IE just displayed the HTML code, maybe IE would be smarter when adding 
a content-type header)
but only w/ firefox.


But the issue has stem from the incomplete read!

Before I had an exhaustive read (via a (read-upto-null) function that I 
found here: http://blog.pettomato.com/), but that gave me win-sock errors,
so I tried the shortcut w/ reading just the 1st line - and that bit me ;)

So I tried this instead of the read for just the 1st line:

===
        (do ((message (read-line client-stream) (read-line client-stream)))
            ( (or    (equal message nil) (= 0 (array-total-size 
message)))    )
               (write-line message))
===

and now it works like a charm.

Thx a lot and best regards,
   Frank


Dan Knapp wrote:

>   Just at a wild guess, are you sure that you're sending CRLF at the 
> end of lines, not just LF?  It doesn't look like you are.  Also, I 
> note that you don't finish reading the headers the client sends... but 
> that probably doesn't matter... unless your response goes out before 
> it's done, perhaps?
>
>   Well, I hope that helps.  I'm curious if that's it, so let us know.
>
> On Nov 10, 2005, at 1:16 AM, fBechmann at t-online.de 
> <mailto:fBechmann at t-online.de> wrote:
>
>> I couldn't get it smaller than this:
>>
>> ===
>>
>> (in-package :cl-user)
>>
>> (load "sys:sockets")
>> (use-package :sb-bsd-sockets)
>>
>> (defmethod handle-client ((socket inet-socket))
>>    "Handle a client request."
>>    (let* ( (client-stream (socket-make-stream socket :input t :output 
>> t :element-type 'character :buffering :full))
>>            (message (read-line client-stream))
>>            (response (format nil
>>                "~A ~D 
>> ~A~%~%<html><head><title>foo</title></head><body>bar!</body></html>~%"
>>                "HTTP/1.0" 200 "OK"
>>                )))
>>            (write-line message)
>>            (write-line response)
>>            (write-line response client-stream))
>>    (write-line "Closing client connection.")
>>    (socket-close socket))
>>   (defun run-http-server (host port)
>>    (let ((s (make-instance 'inet-socket :type :stream :protocol :tcp)))
>>        (socket-bind s (make-inet-address host) port)
>>        (socket-listen s 5)
>>        (do ((client-socket (socket-accept s) (socket-accept s)))
>>            (nil)  ; infinite loop
>>            (write-line "New client")
>>            (let ((client-socket client-socket))
>>                (handle-client client-socket)))))
>>
>> (run-http-server "127.0.0.1" 1975)
>> ;; http://127.0.0.1:1975/foo/bar?bazz=123
>>
>> ===
>>
>> accessing the URL w/ IE doesn't work at all (no http error, just 'The 
>> page cannot be displayed').
>> accessing the URL w/ firefox brings up the page about 4 of 5 times, 
>> but I also get some 'The document contains no data.'.
>> the log output is always displayed in the server console.
>> I'm running ECL fresh from CVS on win2k.
>>
>> I have no idea what's happening here, anyone else?
>>
>> TIA and regards,
>>   frank
>>
>>
>>
>> -------------------------------------------------------
>> SF.Net email is sponsored by:
>> Tame your development challenges with Apache's Geronimo App Server. 
>> Download
>> it for free - -and be entered to win a 42" plasma tv or your very own
>> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
>> _______________________________________________
>> Ecls-list mailing list
>> Ecls-list at lists.sourceforge.net <mailto:Ecls-list at lists.sourceforge.net>
>> https://lists.sourceforge.net/lists/listinfo/ecls-list
>>
>
> -- Dan Knapp
>
>





More information about the ecl-devel mailing list