TcpClient.Available 屬性


取得已從網路接收且可供讀取的資料量。Gets the amount of data that has been received from the network and is available to be read.

 property int Available { int get(); };
public int Available { get; }
member this.Available : int
Public ReadOnly Property Available As Integer


從網路收到的和可供讀取的資料位元組數。The number of bytes of data received from the network and available to be read.


嘗試存取通訊端時發生錯誤。An error occurred when attempting to access the socket.

Socket 已關閉。The Socket has been closed.


下列程式碼範例示範如何使用Available屬性。The following code example shows the use of the Available property.

static void GetAvailable( TcpClient^ t )
   // Find out how many bytes are ready to be read.
   Console::WriteLine( "Available value is {0}", t->Available.ToString() );
static void GetAvailable()
    // Find out how many bytes are ready to be read.
    Console.WriteLine("Availabe value is {0}", t.Available);


Available屬性是一種方法,可判斷資料是否已排入佇列以供讀取。The Available property is a way to determine whether data is queued for reading. 如果有可用的資料, Read請呼叫來取得資料。If data is available, call Read to get the data. 可用的資料是在網路緩衝區中排入佇列以供讀取的總數據量。The available data is the total amount of data queued in the network buffer for reading. 如果網路緩衝區中沒有任何資料排入佇列Available ,則會傳回0。If no data is queued in the network buffer, Available returns 0.

如果遠端主機關閉或關閉連接, Available可能會SocketException擲回。If the remote host shuts down or closes the connection, Available may throw a SocketException. 如果您收到SocketException,請使用SocketException.ErrorCode來取得特定的錯誤碼。If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. 取得此程式碼之後,您可以參考Windows socket 第2版 API 錯誤碼檔,以取得錯誤的詳細描述。After you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.