简体   繁体   中英

How can I get clojure to write a response to a socket?

I've made a socket which will accept any get/post requests on a port.

And for now based on the uri it prints out different strings to the repl.

/ will just say "hello"

/whatever says "hello, whatever"

But now I need to send a response to the browser, this is what I have, but I'm not getting a response in the browser:

(def output (.getOutputStream accepted-socket))

(map (fn[char] (.write @output (int char)))

"HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: 44\nConnection: close\r\n\r\n

<html><body><h1 Please work!/></body></html>")
user=> (import 'java.net.Socket)
java.net.Socket
user=> (def s (Socket. "localhost" 7777))
#'user/s
user=> (with-open [o (io/writer s)]
(.write o "hello, world"))
nil

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM