我创建了一个套接字,它将接受端口上的任何 get/post 请求。
现在根据 uri,它会向 repl 打印出不同的字符串。
/
只会说“你好”
/whatever
表示“你好,随便”
但是现在我需要向浏览器发送响应,这就是我所拥有的,但我在浏览器中没有收到响应:
(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
关于java - 如何让 clojure 向套接字写入响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60121687/