-
-
Notifications
You must be signed in to change notification settings - Fork 214
docs(howto/sockets.po): 翻譯 IPC
與 Using a Socket
區塊
#493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgstr "" | |
"Project-Id-Version: Python 3.11\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2022-06-10 00:16+0000\n" | ||
"PO-Revision-Date: 2023-07-12 02:22+0800\n" | ||
"PO-Revision-Date: 2023-07-19 20:17+0800\n" | ||
"Last-Translator: Jay <[email protected]>\n" | ||
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" | ||
"tw)\n" | ||
|
@@ -231,16 +231,20 @@ msgid "" | |
"a shortcut around a couple of layers of network code and be quite a bit " | ||
"faster." | ||
msgstr "" | ||
"如果你需要在一台機器上的兩個行程間進行快速的行程間通訊 (IPC),你應該考慮使用" | ||
"管道 (pipes) 或共享記憶體 (shared memory)。如果你確定要使用 AF_INET sockets," | ||
"請將「伺服器端」socket 綁定到 ``localhost``。在大多數平台上,這樣將會繞過幾個" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"網路程式碼層,並且速度會更快一些。" | ||
|
||
#: ../../howto/sockets.rst:129 | ||
msgid "" | ||
"The :mod:`multiprocessing` integrates cross-platform IPC into a higher-level " | ||
"API." | ||
msgstr "" | ||
msgstr ":mod:`multiprocessing` 將跨平台的行程間通訊整合到更高層的 API 中。" | ||
|
||
#: ../../howto/sockets.rst:134 | ||
msgid "Using a Socket" | ||
msgstr "" | ||
msgstr "使用一個 Socket" | ||
|
||
#: ../../howto/sockets.rst:136 | ||
msgid "" | ||
|
@@ -252,6 +256,10 @@ msgid "" | |
"in a request, or perhaps a signon. But that's a design decision - it's not a " | ||
"rule of sockets." | ||
msgstr "" | ||
"首先需要注意,網路瀏覽器的「用戶端」socket 和網路伺服器的「用戶端」socket 是" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"非常類似的。也就是說,這是一個「點對點」的通訊方式。或者也可以說\\ *作為設計" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"者,你必須決定通訊的規則*。通常情況下, ``connect`` 的 socket 會通過發送一個" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"請求或者信號來開始一次通訊。但這屬於設計決策,而不是 socket 的規則。" | ||
|
||
#: ../../howto/sockets.rst:143 | ||
msgid "" | ||
|
@@ -264,6 +272,12 @@ msgid "" | |
"reply. Without a ``flush`` in there, you may wait forever for the reply, " | ||
"because the request may still be in your output buffer." | ||
msgstr "" | ||
"現在有兩組可供通訊使用的動詞。你可以使用 ``send`` 和 ``recv``,或者可以將用戶" | ||
"端 socket 轉換成類似文件的形式,並使用 ``read`` 和 ``write``。後者是 Java 中" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"呈現 socket 的方式。我不打算在這裡討論它,只是提醒你需要在 socket 上使用 " | ||
"``flush``。這些是緩衝的「文件」,一個常見的錯誤是使用 ``write`` 寫入某些內" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"容,然後直接 ``read`` 回覆。如果不使用 ``flush``,你可能會一直等待這個回覆," | ||
"因為請求可能還在你的輸出緩衝中。" | ||
|
||
#: ../../howto/sockets.rst:152 | ||
msgid "" | ||
|
@@ -275,6 +289,11 @@ msgid "" | |
"you how many bytes they handled. It is *your* responsibility to call them " | ||
"again until your message has been completely dealt with." | ||
msgstr "" | ||
"現在我們來到 sockets 的主要障礙 - ``send`` 和 ``recv`` 操作的是網路緩衝區。他" | ||
"們不一定會處理你提供給它們的所有位元組(或者是你期望它處理的位元組),因為它" | ||
"們主要的重點是處理網路緩衝區。一般來說,它們會在關聯的網路衝區已滿 " | ||
"(``send``) 或已清空 (``recv``) 時回傳。然後告訴你它們處理了多少位元組。\\ *你" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"* \\的責任是一直呼叫它們直到你所有的訊息處理完成。" | ||
|
||
#: ../../howto/sockets.rst:160 | ||
msgid "" | ||
|
@@ -283,13 +302,19 @@ msgid "" | |
"data on this connection. Ever. You may be able to send data successfully; " | ||
"I'll talk more about this later." | ||
msgstr "" | ||
"當 ``recv`` 回傳 0 個位元組時,就表示另一端已經關閉(或著它所在的行程正在關" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"閉)連接。你再也不能從這個連接上取得任何數據了。你可能還是可以成功發送數據;" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"我稍後會對此進行更詳細的解釋。" | ||
|
||
#: ../../howto/sockets.rst:165 | ||
msgid "" | ||
"A protocol like HTTP uses a socket for only one transfer. The client sends a " | ||
"request, then reads a reply. That's it. The socket is discarded. This means " | ||
"that a client can detect the end of the reply by receiving 0 bytes." | ||
msgstr "" | ||
"像 HTTP 這樣的協議只使用一個 socket 進行一次傳輸。用戶端發送一個請求,然後讀" | ||
"取一個回覆。就這樣。然後這個 socket 就會被銷毀。這表示者用戶端可以通過接收 0 " | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"個位元組來檢測回覆的結束。" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../howto/sockets.rst:169 | ||
msgid "" | ||
|
@@ -304,12 +329,23 @@ msgid "" | |
"they are* (much better), *or end by shutting down the connection*. The " | ||
"choice is entirely yours, (but some ways are righter than others)." | ||
msgstr "" | ||
"但是如果你打算在之後的傳輸中重新利用 socket 的話,你需要明白\\ *socket 中是不" | ||
"存在* \\ :abbr:`EOT (傳輸結束)`。重申一次:如果一個 socket 的 ``send`` 或 " | ||
"``recv`` 處理了 0 個位元組後回傳,表示連接已經斷開。如果連接\\ *沒有* \\斷" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"開,你可能會永遠處於等待 ``recv`` 的狀態,因為(就目前來說)socket *不會* " | ||
"\\告訴你沒有更多數據可以讀取了。現在,如果你稍微思考一下,你就會意識到 " | ||
"socket 的一個基本事實:*訊息要麼是一個固定的長度(不好的做法),要麼是可以被" | ||
"分隔的(普通的做法),要麼是指定其長度(更好地做法),要麼通過關閉連接來結" | ||
"束。* \\完全由你來決定要使用哪種方式(但有些方法比其他方法來的更好)。" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../howto/sockets.rst:180 | ||
msgid "" | ||
"Assuming you don't want to end the connection, the simplest solution is a " | ||
"fixed length message::" | ||
msgstr "" | ||
"假設你不想結束連接,最簡單的方式就是使用固定長度的訊息:\n" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"\n" | ||
"::" | ||
|
||
#: ../../howto/sockets.rst:217 | ||
msgid "" | ||
|
@@ -319,6 +355,10 @@ msgid "" | |
"gets more complex. (And in C, it's not much worse, except you can't use " | ||
"``strlen`` if the message has embedded ``\\0``\\ s.)" | ||
msgstr "" | ||
"發送部分的程式碼幾乎可用於任何訊息的傳送方式 - 在 Python 中你發送一個字串,可" | ||
"以用 ``len()`` 來確認他的長度(即使字串包含了 ``\\0`` 字元)。在這裡,主要是" | ||
"接收的程式碼變得更複雜一些。(在 C 語言中,情況沒有變得更糟,只是如果訊息中包" | ||
"含了 ``\\0`` 字元,你就不能使用 ``strlen`` 函式。)" | ||
|
||
#: ../../howto/sockets.rst:223 | ||
msgid "" | ||
|
@@ -330,6 +370,11 @@ msgid "" | |
"chunk size, (4096 or 8192 is frequently a good match for network buffer " | ||
"sizes), and scanning what you've received for a delimiter." | ||
msgstr "" | ||
"最簡單的改進方法是將訊息的第一個字元表示訊息的類型,並根據訊息的類型來決定訊" | ||
"息的長度。現在你需要使用兩次 ``recv`` - 第一次用於接收(至少)第一個字元來得" | ||
"知長度,第二次用於在迴圈中接收剩下的訊息。如果你決定使用分隔符的方式,你將會" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"以某個任意的區塊大小進行接收(4096 或 8192 通常是網路緩衝區大小的良好選擇)," | ||
"並在收到的內容中掃描分隔符號。" | ||
|
||
#: ../../howto/sockets.rst:231 | ||
msgid "" | ||
|
@@ -339,6 +384,9 @@ msgid "" | |
"of a following message. You'll need to put that aside and hold onto it, " | ||
"until it's needed." | ||
msgstr "" | ||
"需要注意的一個複雜情況是,如果你的通訊協議允許連續發送多個訊息(沒有任何回" | ||
"應),並且你傳遞給 ``recv`` 函式一個任意的區塊大小,你可能會因為讀取到後續接" | ||
"收的訊息而停止讀取。你需要將其放在一旁並保留下來,直到需要使用的時候。" | ||
weijay0804 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#: ../../howto/sockets.rst:237 | ||
msgid "" | ||
|
@@ -351,13 +399,21 @@ msgid "" | |
"not always manage to get rid of everything in one pass. And despite having " | ||
"read this, you will eventually get bit by it!" | ||
msgstr "" | ||
"使用長度作為訊息的前綴(例如,使用 5 個數字字元表示)會變得更複雜,因為(信不" | ||
"信由你)你可能無法在一次 ``recv`` 中獲得所有 5 個字元。在一般使用下,可能不會" | ||
"有這個狀況,但在高負載的網路下,除非使用兩個 ``recv`` (第一個用於確定長度," | ||
"第二個用於取得訊息的資料部分),否則你的程式碼很快就會出現錯誤。這令人非常頭" | ||
"痛。同樣的情況也會讓你發現 ``send`` 並不總能在一次傳輸中完全清除所有內容。儘" | ||
"管已經閱讀了這篇文章,但最終還是無法解決!" | ||
|
||
#: ../../howto/sockets.rst:246 | ||
msgid "" | ||
"In the interests of space, building your character, (and preserving my " | ||
"competitive position), these enhancements are left as an exercise for the " | ||
"reader. Lets move on to cleaning up." | ||
msgstr "" | ||
"為了節省篇幅、培養你的技能(並保持我的競爭優勢),這些改進方法留給讀者自行練" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. building your character 直翻是塑造你的風格、特色之意,但要這樣翻也沒有偏離太多。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 當初是想説因為後面那句「這些改進方法留給讀者自行練習」所以想說翻成「培養你的技能」會比較順暢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 了解,這邊應該不是什麼大問題。 |
||
"習。現在讓我們開始進行清理工作。" | ||
|
||
#: ../../howto/sockets.rst:252 | ||
msgid "Binary Data" | ||
|
Uh oh!
There was an error while loading. Please reload this page.