TransmitFileOptions 列舉

定義

TransmitFileOptions 列舉型別 (Enumeration) 定義檔案傳輸要求中使用的值。

此列舉支援其成員值的位元組合。

C#
[System.Flags]
public enum TransmitFileOptions
繼承
TransmitFileOptions
屬性

欄位

名稱 Description
Disconnect 1

所有檔案資料都已加入佇列準備傳送後,啟動傳輸層中斷連接。 與 ReuseSocket 搭配使用時,在傳送檔案之後,這些旗標會將通訊端返回至中斷連接、可重複使用的狀態。

ReuseSocket 2

完成要求後,可以重複使用通訊端控制代碼。 只有在同時指定 Disconnect 時,這個旗標才有效。 與 Disconnect 搭配使用時,在傳送檔案之後,這些旗標會將通訊端返回至中斷連接、可重複使用的狀態。

UseDefaultWorkerThread 0

使用預設執行緒處理過長的檔案傳輸要求。

UseKernelApc 32

使用核心非同步程序呼叫 (APC) 替代背景工作執行緒 (Worker Thread),處理過長的檔案傳輸要求。 過長要求的定義是需要多次讀取檔案或快取的要求,也就是要求要視檔案的大小和傳送封包的指定長度而定。

UseSystemThread 16

使用系統執行緒處理過長的檔案傳輸要求。

WriteBehind 4

立即完成檔案傳輸要求,無暫止。 如果指定這個旗標,且檔案傳輸成功,則系統已經接受資料,而沒有必要得到遠端的通知。 請勿將這個旗標與 DisconnectReuseSocket 旗標搭配使用。

範例

下列範例示範 在 TransmitFileOptionsSocket.SendFile的呼叫中使用 。 test.txt 檔案位於本機電腦的根目錄中。 在此範例中,會建立預先緩衝器和後置數據,並使用檔案傳送至遠端主機。 若要使用系統預設線程, UseDefaultWorkerThread 請指定 。

C#
// Establish the local endpoint for the socket.
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress  ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);

// Create a TCP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
        SocketType.Stream, ProtocolType.Tcp);

// Connect the socket to the remote endpoint.
client.Connect(ipEndPoint);

// Send file fileName to the remote host with preBuffer and postBuffer data.
// There is a text file test.txt located in the root directory.
string fileName = "C:\\test.txt";

// Create the preBuffer data.
string string1 = String.Format("This is text data that precedes the file.{0}", Environment.NewLine);
byte[] preBuf = Encoding.ASCII.GetBytes(string1);

// Create the postBuffer data.
string string2 = String.Format("This is text data that will follow the file.{0}", Environment.NewLine);
byte[] postBuf = Encoding.ASCII.GetBytes(string2);

//Send file fileName with buffers and default flags to the remote device.
Console.WriteLine("Sending {0} with buffers to the host.{1}", fileName, Environment.NewLine);
client.SendFile(fileName, preBuf, postBuf, TransmitFileOptions.UseDefaultWorkerThread);

// Release the socket.
client.Shutdown(SocketShutdown.Both);
client.Close();

備註

備註

旗標 Disconnect ,並將 ReuseSocket 套接字傳回至傳輸檔案之後已中斷連線且可重複使用的狀態。 這些旗標不應用於要求服務品質 (QOS) 的套接字上,因為服務提供者可能會在文件傳輸完成之前立即刪除與套接字相關聯的任何服務品質。 啟用 QOS 的套接字最佳方法是在檔案傳輸完成時呼叫 Socket.Close ,而不是依賴這些旗標。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1