This documentation is archived and is not being maintained.

Socket.IOControl Method

Sets low-level operating modes for the Socket.

[Visual Basic]
Public Function IOControl( _
   ByVal ioControlCode As Integer, _
   ByVal optionInValue() As Byte, _
   ByVal optionOutValue() As Byte _
) As Integer
public int IOControl(
 int ioControlCode,
 byte[] optionInValue,
 byte[] optionOutValue
public: int IOControl(
 int ioControlCode,
 unsigned char optionInValue __gc[],
 unsigned char optionOutValue __gc[]
public function IOControl(
   ioControlCode : int,
 optionInValue : Byte[],
 optionOutValue : Byte[]
) : int;


The control code of the operation to perform.
An array of type Byte that contains the input data required by the operation.
An array of type Byte that contains the output data returned by the operation.

Return Value

The number of bytes in the optionOutValue parameter.


Exception Type Condition
SocketException An error occurred when attempting to access the socket. See the Remarks section for more information.
ObjectDisposedException The Socket has been closed.
InvalidOperationException An attempt was made to change the blocking mode without using the Blocking property.
SecurityException A caller in the call stack does not have the required permissions.


The IOControl method provides low-level access to the operating system Socket underlying the current instance of the Socket class. For more information about IOControl, see the WSAIoctl documentation in MSDN.

Note   If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Socket Version 2 API error code documentation in MSDN for a detailed description of the error.


[C#, C++] The following code example compares the results of FIONREAD and the Available property.

// FIONREAD is also available as the "Available" property.
       public const int FIONREAD   = 0x4004667F;
       static void DisplayPendingByteCount(Socket s)
    byte[] outValue = BitConverter.GetBytes(0);

    // Check how many bytes have been received.
    s.IOControl(FIONREAD, null, outValue);
    uint bytesAvailable = BitConverter.ToUInt32(outValue, 0);
    Console.WriteLine("server has {0} bytes pending. Available property says {1}.",
        bytesAvailable, s.Available);

// FIONREAD is also available as the "Available" property.
const int FIONREAD   = 0x4004667F;

void DisplayPendingByteCount(Socket* s)
    Byte outValue[] = BitConverter::GetBytes(0);

    // Check how many bytes have been received.
    s->IOControl(FIONREAD, 0, outValue);

    UInt32 bytesAvailable = BitConverter::ToUInt32(outValue, 0);
    Console::WriteLine(S"server has {0} bytes pending. Available property says {1}.", __box(bytesAvailable), __box(s->Available));


[Visual Basic, JScript] No example is available for Visual Basic or JScript. To view a C# or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Socket Class | Socket Members | System.Net.Sockets Namespace