On Mon, Dec 8, 2008 at 5:18 PM, prhlava <[EMAIL PROTECTED]> wrote: > > > Well, it turns out that the following works, but it only prints the > "exchange" to stdout, > if the code is cut and pasted to the REPL but _not_ if run as .clj > script)...
I have gotten your example to work with a bit of reading and modification (and thank you, I was after an example http server, this got me going): (import '(java.io IOException OutputStream) '(java.util Iterator List Set) '(com.sun.net.httpserver Headers HttpExchange HttpHandler) '(java.net InetSocketAddress) '(java.util.concurrent Executors) '(com.sun.net.httpserver HttpServer)) (defn handle-http-exchange [#^HttpExchange exchange] (try (do (let [hdrs (.getResponseHeaders exchange)] (.add hdrs "Content-type: " "text/plain")) (.sendResponseHeaders exchange 200 0) (let [out (java.io.PrintStream. (.getResponseBody exchange))] (.println out (str "Time time is: " (java.util.Date.))) (.close out))) (catch Throwable ex (println (str "Error: " ex))))) (defn start-server [port] (let [server (. HttpServer create (new InetSocketAddress port) 0) handler (proxy [HttpHandler] [] (handle [#^HttpExchange exchange] (handle-http-exchange exchange)))] (. server createContext "/" handler) (. server setExecutor (. Executors newCachedThreadPool)) (. server start) (print "server listening on port: ") (println port) server)) (def server (start-server 8080)) ;; (.stop server 0) Regards, Kyle R. Burton --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---