SocketFlags 枚举

定义

指定套接字发送和接收行为。

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

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

字段

Broadcast 1024

指示广播数据包。

ControlDataTruncated 512

指示控制数据无法放入 64 KB 的内部缓冲区且已被截断。

DontRoute 4

不使用路由表进行发送。

MaxIOVectorLength 16

提供用于发送和接收数据的 WSABUF 结构数的标准值。 .NET Framework 4.5 上不使用或不支持此值。

Multicast 2048

指示多播数据包。

None 0

不对此调用使用任何标志。

OutOfBand 1

处理带外数据。

Partial 32768

部分发送或接收消息。

Peek 2

快速查看传入消息。

Truncated 256

消息太大,无法放入指定的缓冲区,并且已被截断。

示例

以下示例发送数据并指定 SocketFlags.None

// Displays sending with a connected socket
// using the overload that takes a buffer, message size, and socket flags.
int SendReceiveTest3( Socket^ server )
{
   array<Byte>^ msg = Encoding::UTF8->GetBytes( "This is a test" );
   array<Byte>^ bytes = gcnew array<Byte>(256);
   try
   {
      // Blocks until send returns.
      int i = server->Send( msg, msg->Length, SocketFlags::None );
      Console::WriteLine( "Sent {0} bytes.", i.ToString() );
      
      // Get reply from the server.
      int byteCount = server->Receive( bytes, server->Available,
         SocketFlags::None );
      if ( byteCount > 0 )
      {
         Console::WriteLine( Encoding::UTF8->GetString( bytes ) );
      }
   }
   catch ( SocketException^ e ) 
   {
      Console::WriteLine( "{0} Error code: {1}.", e->Message, e->ErrorCode.ToString() );
      return (e->ErrorCode);
   }
   return 0;
}
// Displays sending with a connected socket
// using the overload that takes a buffer, message size, and socket flags.
public static int SendReceiveTest3(Socket server)
{
    byte[] msg = Encoding.UTF8.GetBytes("This is a test");
    byte[] bytes = new byte[256];
    try
    {
        // Blocks until send returns.
        int i = server.Send(msg, msg.Length, SocketFlags.None);
        Console.WriteLine("Sent {0} bytes.", i);

        // Get reply from the server.
        int byteCount = server.Receive(bytes, bytes.Length, SocketFlags.None);
        if (byteCount > 0)
            Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, byteCount));
    }
    catch (SocketException e)
    {
        Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode);
        return (e.ErrorCode);
    }
    return 0;
}
' Displays sending with a connected socket
' using the overload that takes a buffer, message size, and socket flags.
Public Shared Function SendReceiveTest3(ByVal server As Socket) As Integer 
    Dim msg As Byte() = Encoding.UTF8.GetBytes("This is a test")
    Dim bytes(255) As Byte
    Try
        ' Blocks until send returns.
        Dim i As Integer = server.Send(msg, msg.Length, SocketFlags.None)
        Console.WriteLine("Sent {0} bytes.", i)
        
        ' Get reply from the server.
        Dim byteCount As Integer = server.Receive(bytes, server.Available, SocketFlags.None)
        If byteCount > 0 Then
            Console.WriteLine(Encoding.UTF8.GetString(bytes))
        End If
    Catch e As SocketException
        Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode)
        Return e.ErrorCode
    End Try
    Return 0

End Function 'SendReceiveTest3

适用于