TransmitFileOptions 枚举

定义

TransmitFileOptions 枚举定义文件传输请求中使用的值。

此枚举支持其成员值的按位组合。

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

字段

名称 说明
UseDefaultWorkerThread 0

使用默认线程处理长文件传输请求。

Disconnect 1

在所有文件数据已排队进行传输后,启动传输级别断开连接。 与 一起使用 ReuseSocket时,这些标志会将套接字返回到传输文件后断开连接的可重用状态。

ReuseSocket 2

当请求完成时,可以重复使用套接字句柄。 仅当还指定了此标志时 Disconnect ,此标志才有效。 与 一起使用 Disconnect时,这些标志会将套接字返回到传输文件后断开连接的可重用状态。

WriteBehind 4

立即完成文件传输请求,无需挂起。 如果指定了此标志并且文件传输成功,则系统已接受数据,但不一定由远程端确认。 请勿将此标志与标志Disconnect一起使用ReuseSocket

UseSystemThread 16

使用系统线程处理长文件传输请求。

UseKernelApc 32

使用内核异步过程调用(APC)而不是工作线程来处理长文件传输请求。 长请求定义为需要从文件或缓存中读取多个请求;因此,请求取决于文件大小和发送数据包的指定长度。

示例

下面的示例演示如何 TransmitFileOptions 在调用 Socket.SendFile中使用 。 文件“test.txt”位于本地计算机的根目录中。 在此示例中,会创建一个预先填充和后缀的数据,并使用该文件发送到远程主机。 若要使用系统的默认线程, UseDefaultWorkerThread 请指定。

// 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 ,而不是依赖这些标志。

适用于