System.Net.Sockets.Socket.IOControl Method

Sets low-level operating modes for the System.Net.Sockets.Socket using numerical control codes.

Syntax

public int IOControl (int ioctl_code, byte[] in_value, byte[] out_value)

Parameters

ioctl_code
Documentation for this section has not yet been entered.
in_value
Documentation for this section has not yet been entered.
out_value
Documentation for this section has not yet been entered.

Returns

The number of bytes in the optionOutValue parameter.

Exceptions

TypeReason
InvalidOperationException

An attempt was made to change the blocking mode.

Note:

Use the Socket.Blocking property to change the blocking mode.

System.Net.Sockets.SocketException
Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.
ObjectDisposedExceptionThe current instance has been disposed.
System.Security.SecurityExceptionA caller in the call stack does not have the required permissions.

Remarks

The Socket.IOControl(int, Byte[], Byte[]) method provides low-level access to the operating system System.Net.Sockets.Socket underlying the current instance of the System.Net.Sockets.Socket class. For more information, see the WSAIoctl documentation in the MSDN library.

Note:

If you receive a System.Net.Sockets.SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

Permissions

Example

The following example gets the number of bytes of available data to be read and writes the result to the console on a Windows system. The remote endpoint (remoteEndpoint) to connect to might need to be changed to a value that is valid on the current system.

C# Example

using System;
using System.Net;
using System.Net.Sockets;

class App {

  static void Main() {

    IPAddress remoteAddress =
    Dns.Resolve(Dns.GetHostName()).AddressList[0];

    IPEndPoint remoteEndpoint =
      new IPEndPoint(remoteAddress, 80);

    Socket someSocket =
      new Socket(AddressFamily.InterNetwork,
                 SocketType.Stream,
                 ProtocolType.Tcp);

    someSocket.Connect(remoteEndpoint);

    int fionRead = 0x4004667F;
    byte[]inValue = {0x00, 0x00, 0x00, 0x00};
    byte[]outValue = {0x00, 0x00, 0x00, 0x00};

    someSocket.IOControl(fionRead, inValue, outValue);

    uint bytesAvail = BitConverter.ToUInt32(outValue, 0);
      
    Console.WriteLine(
      "There are {0} bytes available to be read.",
      bytesAvail.ToString() );
  }
}
      

The output is

There are 0 bytes available to be read.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0