1

このコードでは

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
4

2 に答える 2

2

新しいクライアントが接続するまでブロックしwaitます。listen-portそれが発生すると、単純に を返しますlisten-port。次にfirst、新しく接続されたクライアントに対応するポートを取得します。この後、次の 2 つの異なるポートがあります。listen-portはサーバーがさらに接続するためにリッスンするhttp-portポートで、 は新しく接続されたクライアントと通信するためのポートです。

バージョン 2.3 の REBOL/Core ユーザーズ ガイドの「Creating TCP Servers」セクションは、この点に関してはまだ完全に最新です。

于 2009-08-18T20:17:54.863 に答える
0

waitlisten-portにアクティビティが発生するまでブロックしてから、を返しますlisten-port

したがって、firstからデータの最初の行を取得して返しますlisten-port

ドキュメントで説明されています(ただし簡単に)。

于 2009-08-18T00:43:43.157 に答える