Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -0,0 +1,7 @@
|
|||
(ql:quickload :hunchentoot)
|
||||
(defpackage :hello-web (:use :cl :hunchentoot))
|
||||
(in-package :hello-web)
|
||||
|
||||
(define-easy-handler (hello :uri "/") () "Goodbye, World!")
|
||||
|
||||
(defparameter *server* (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 8080)))
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
(ql:quickload :usocket)
|
||||
(defpackage :hello-web-manual (:use :cl :usocket))
|
||||
(in-package :hello-web-manual)
|
||||
|
||||
(defun crlf (&optional (stream *standard-output*))
|
||||
(write-char #\return stream)
|
||||
(write-char #\linefeed stream)
|
||||
(values))
|
||||
|
||||
(defun ln (string &optional (stream *standard-output*))
|
||||
(write-string string stream)
|
||||
(crlf stream))
|
||||
|
||||
(defun read-all (stream)
|
||||
(loop for char = (read-char-no-hang stream nil :eof)
|
||||
until (or (null char) (eq char :eof)) collect char into msg
|
||||
finally (return (values msg char))))
|
||||
|
||||
(defun serve (port &optional (log-stream *standard-output*))
|
||||
(let ((connections (list (socket-listen "127.0.0.1" port :reuse-address t))))
|
||||
(unwind-protect
|
||||
(loop (loop for ready in (wait-for-input connections :ready-only t)
|
||||
do (if (typep ready 'stream-server-usocket)
|
||||
(push (socket-accept ready) connections)
|
||||
(let* ((stream (socket-stream ready)))
|
||||
(read-all stream)
|
||||
(format log-stream "Got message...~%")
|
||||
(mapc (lambda (line) (ln line stream))
|
||||
(list "HTTP/1.1 200 OK"
|
||||
"Content-Type: text/plain; charset=UTF-8"
|
||||
""
|
||||
"Hello world!"))
|
||||
(socket-close ready)
|
||||
(setf connections (remove ready connections))))))
|
||||
(loop for c in connections do (loop while (socket-close c))))))
|
||||
|
||||
(serve 8080)
|
||||
|
|
@ -17,3 +17,4 @@ for (;;) {
|
|||
}
|
||||
else usleep(100000); // limits CPU usage by sleeping after doing every request
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
import java.io.PrintWriter
|
||||
import java.net.ServerSocket
|
||||
|
||||
object HelloWorld extends App {
|
||||
|
||||
val text =
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Hello world </TITLE>
|
||||
</HEAD>
|
||||
<BODY LANG="en-US" BGCOLOR="#e6e6ff" DIR="LTR">
|
||||
<P ALIGN="CENTER"> <FONT FACE="Arial, sans-serif" SIZE="6">Goodbye, World!</FONT> </P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
val port = 8080
|
||||
val listener = new ServerSocket(port)
|
||||
printf("Listening at port %1$d", port)
|
||||
|
||||
while (true) {
|
||||
val sock = listener.accept()
|
||||
new PrintWriter(sock.getOutputStream(), true).println(text)
|
||||
sock.close()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue