1 out of 11 rated this helpful - Rate this topic

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)

[FlagsAttribute] 
public enum SocketFlags
/** @attribute FlagsAttribute() */ 
public enum SocketFlags
FlagsAttribute 
public enum SocketFlags
  Member name Description
Broadcast Indicates a broadcast packet. 
ControlDataTruncated Indicates that the control data did not fit into an internal 64-KB buffer and was truncated. 
Supported by the .NET Compact Framework DontRoute Send without using routing tables. 
Supported by the .NET Compact Framework MaxIOVectorLength Provides a standard value for the number of WSABUF structures that are used to send and receive data. 
Multicast  
Supported by the .NET Compact Framework None Use no flags for this call. 
Supported by the .NET Compact Framework OutOfBand Process out-of-band data. 
Supported by the .NET Compact Framework Partial Partial send or receive for message. 
Supported by the .NET Compact Framework Peek Peek at the incoming message. 
Truncated The message was too large to fit into the specified buffer and was truncated. 

The following example sends data and specifies None for SocketFlags.

// 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;
}

// Displays sending with a connected socket
// using the overload that takes a buffer, message size, and socket flags.
public static int SendReceiveTest3(Socket server)
{
    ubyte msg[] = Encoding.get_UTF8().GetBytes("This is a test");
    ubyte bytes[] = new ubyte[256];
    try {
        // Blocks until send returns.
        int i = server.Send(msg, msg.get_Length(), SocketFlags.None);
        Console.WriteLine("Sent {0} bytes.", (Int32)i);
        // Get reply from the server.
        server.Receive(bytes, server.get_Available(), SocketFlags.None);
        Console.WriteLine(Encoding.get_UTF8().GetString(bytes));
    }
    catch (SocketException e) {
        Console.WriteLine("{0} Error code: {1}.", e.get_Message(),
            (Int32)e.get_ErrorCode());
        return e.get_ErrorCode();
    }
    return 0;
} //SendReceiveTest3

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ