TransmitFileOptions 列舉

定義

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

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

public enum class TransmitFileOptions
[System.Flags]
public enum TransmitFileOptions
[<System.Flags>]
type TransmitFileOptions = 
Public Enum TransmitFileOptions
繼承
TransmitFileOptions
屬性

欄位

Disconnect 1

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

ReuseSocket 2

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

UseDefaultWorkerThread 0

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

UseKernelApc 32

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

UseSystemThread 16

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

WriteBehind 4

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

範例

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

// Establish the local endpoint for the socket.
IPHostEntry^ ipHost = Dns::GetHostEntry( Dns::GetHostName() );
IPAddress^ ipAddr = ipHost->AddressList[ 0 ];
IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddr,11000 );

// Create a TCP socket.
Socket^ client = gcnew 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 );
array<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 );
array<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();
// 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 ,而不是依賴這些旗標。

適用於