.NET Framework Class Library
SocketFlags Enumeration

Specifies socket send and receive behaviors.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
<FlagsAttribute> _
Public Enumeration SocketFlags
Visual Basic (Usage)
Dim instance As SocketFlags
C#
[FlagsAttribute]
public enum SocketFlags
Visual C++
[FlagsAttribute]
public enum class SocketFlags
JScript
public enum SocketFlags
Members

Member nameDescription
Supported by the .NET Compact FrameworkNoneUse no flags for this call.
Supported by the .NET Compact FrameworkOutOfBandProcess out-of-band data.
Supported by the .NET Compact FrameworkPeekPeek at the incoming message.
Supported by the .NET Compact FrameworkDontRouteSend without using routing tables.
Supported by the .NET Compact FrameworkMaxIOVectorLengthProvides a standard value for the number of WSABUF structures that are used to send and receive data.
TruncatedThe message was too large to fit into the specified buffer and was truncated.
ControlDataTruncatedIndicates that the control data did not fit into an internal 64-KB buffer and was truncated.
BroadcastIndicates a broadcast packet.
MulticastIndicates a multicast packet.
Supported by the .NET Compact FrameworkPartialPartial send or receive for message.
Examples

The following example sends data and specifies None for SocketFlags.

Visual Basic
' 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

C#
// 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, 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);
        return (e.ErrorCode);
    }
    return 0;
}
Visual C++
// 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;
}
CPP_OLD
 // Displays sending with a connected socket
 // using the overload that takes a buffer, message size, and socket flags.
int SendReceiveTest3(Socket* server)
 {
     Byte msg[]= Encoding::UTF8->GetBytes(S"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(S"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(S"{0} Error code: {1}.", e->Message, e->ErrorCode.ToString());
         return (e->ErrorCode);
     }
     return 0;
 }
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
See Also

Reference

Tags :


Page view tracker