Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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
[C#]
public int IOControl(
 int ioControlCode,
 byte[] optionInValue,
 byte[] optionOutValue
);
[C++]
public: int IOControl(
 int ioControlCode,
 unsigned char optionInValue __gc[],
 unsigned char optionOutValue __gc[]
);
[JScript]
public function IOControl(
   ioControlCode : int,
 optionInValue : Byte[],
 optionOutValue : Byte[]
) : int;

Parameters

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

Return Value

The number of bytes in the optionOutValue parameter.

Exceptions

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.

Remarks

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.

Example

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

[C#] 
// 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);
    
    return;
}

[C++] 
// 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));

    return;
}

[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.

Requirements

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft