Socket.IOControl 方法

定義

設定 Socket 的低階作業系統模式。

多載

IOControl(Int32, Byte[], Byte[])

使用數值控制碼,設定 Socket 的低階作業模式。

IOControl(IOControlCode, Byte[], Byte[])

使用 Socket 列舉型別指定控制碼,以設定 IOControlCode 的低階作業模式。

IOControl(Int32, Byte[], Byte[])

來源:
Socket.cs
來源:
Socket.cs
來源:
Socket.cs

使用數值控制碼,設定 Socket 的低階作業模式。

public:
 int IOControl(int ioControlCode, cli::array <System::Byte> ^ optionInValue, cli::array <System::Byte> ^ optionOutValue);
public int IOControl (int ioControlCode, byte[]? optionInValue, byte[]? optionOutValue);
public int IOControl (int ioControlCode, byte[] optionInValue, byte[] optionOutValue);
member this.IOControl : int * byte[] * byte[] -> int
Public Function IOControl (ioControlCode As Integer, optionInValue As Byte(), optionOutValue As Byte()) As Integer

參數

ioControlCode
Int32

Int32 值,指定要執行之作業的控制碼。

optionInValue
Byte[]

Byte 陣列,包含作業所需的輸入資料。

optionOutValue
Byte[]

Byte 陣列,包含作業傳回的輸出資料。

傳回

optionOutValue 中的位元組數。

例外狀況

嘗試存取通訊端時發生錯誤。

已嘗試不使用 Blocking 屬性來變更封鎖模式。

呼叫堆疊中的呼叫端沒有所需的使用權限。

範例

下列程式碼範例會比較 FIONREAD 和 Available 屬性的結果。

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

void DisplayPendingByteCount( Socket^ s )
{
   array<Byte>^ outValue = BitConverter::GetBytes( 0 );
   
   // Check how many bytes have been received.
   s->IOControl( FIONREAD, nullptr, outValue );

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

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

備註

方法 IOControl 提供對目前 類別實例基礎之作業系統 SocketSocket 低階存取。 如需詳細資訊,請參閱 WSAIoctl 檔。

注意

如果您收到 SocketException ,請使用 SocketException.ErrorCode 屬性來取得特定的錯誤碼。 取得此程式碼之後,請參閱 Windows Sockets 第 2 版 API 錯誤碼 檔,以取得錯誤的詳細描述。

注意

在應用程式中啟用網路追蹤時,這個成員會輸出追蹤資訊。 如需詳細資訊,請參閱.NET Framework 中的網路追蹤

適用於

IOControl(IOControlCode, Byte[], Byte[])

來源:
Socket.cs
來源:
Socket.cs
來源:
Socket.cs

使用 Socket 列舉型別指定控制碼,以設定 IOControlCode 的低階作業模式。

public:
 int IOControl(System::Net::Sockets::IOControlCode ioControlCode, cli::array <System::Byte> ^ optionInValue, cli::array <System::Byte> ^ optionOutValue);
public int IOControl (System.Net.Sockets.IOControlCode ioControlCode, byte[]? optionInValue, byte[]? optionOutValue);
public int IOControl (System.Net.Sockets.IOControlCode ioControlCode, byte[] optionInValue, byte[] optionOutValue);
member this.IOControl : System.Net.Sockets.IOControlCode * byte[] * byte[] -> int
Public Function IOControl (ioControlCode As IOControlCode, optionInValue As Byte(), optionOutValue As Byte()) As Integer

參數

ioControlCode
IOControlCode

IOControlCode 值,指定要執行之作業的控制碼。

optionInValue
Byte[]

Byte 型別的陣列,包含作業所需的輸入資料。

optionOutValue
Byte[]

Byte 型別的陣列,包含作業傳回的輸出資料。

傳回

optionOutValue 中的位元組數。

例外狀況

嘗試存取通訊端時發生錯誤。

已嘗試不使用 Blocking 屬性來變更封鎖模式。

範例

下列程式碼範例會比較呼叫 IOControlDataToRead 與 和 Available 屬性的結果。

void DisplayPendingByteCount( Socket^ s )
{
   array<Byte>^ outValue = BitConverter::GetBytes( 0 );
   
   // Check how many bytes have been received.
   s->IOControl( IOControlCode::DataToRead, nullptr, outValue );

   UInt32 bytesAvailable = BitConverter::ToUInt32( outValue, 0 );
   Console::Write( "server has {0} bytes pending,",
      bytesAvailable );
   Console::WriteLine( "Available property says {1}.",
      s->Available );
   return;
}
static void DisplayPendingByteCount(Socket s)
{
    byte[] outValue = BitConverter.GetBytes(0);

    // Check how many bytes have been received.
    s.IOControl(IOControlCode.DataToRead, null, outValue);

    uint bytesAvailable = BitConverter.ToUInt32(outValue, 0);
    Console.Write("server has {0} bytes pending. ",
        bytesAvailable);
    Console.WriteLine("Available property says {1}.",
                     s.Available);

    return;
}

備註

這個方法提供對目前 類別實例基礎之作業系統 SocketSocket 低階存取。 如需詳細資訊,請參閱 WSAIoctl 檔。

注意

如果您收到 SocketException ,請使用 SocketException.ErrorCode 屬性來取得特定的錯誤碼。 取得此程式碼之後,請參閱 Windows Sockets 第 2 版 API 錯誤碼 檔,以取得錯誤的詳細描述。

注意

在應用程式中啟用網路追蹤時,這個成員會輸出追蹤資訊。 如需詳細資訊,請參閱.NET Framework 中的網路追蹤

適用於