在此代码Rebol的最小的HTTP服务器:为什么先等待监听端口?
web-dir: %./www/ ; the path to rebol www subdirectory
listen-port: open/lines tcp://:80 ; port used for web connections
buffer: make string! 1024 ; will auto-expand if needed
forever [
http-port: first wait listen-port
while [not empty? client-request: first http-port][
repend buffer [client-request newline]
]
repend buffer ["Address: " http-port/host newline]
parse buffer ["get" ["http" | "/ " | copy file to " "]]
parse file [thru "." [
"html" (mime: "text/html") |
"txt" (mime: "text/plain")
]
]
data: read/binary web-dir/:file
insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
write-io http-port data length? data
close http-port
]
为什么首先在
http-port: first wait listen-port
,而不是仅仅
http-port: wait listen-port
谢谢,似乎更清楚,我:) – 2009-08-18 22:22:20