UdpClient.Available UdpClient.Available UdpClient.Available UdpClient.Available Property

定義

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

public:
 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.

例外狀況

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

範例

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

static void GetAvailable( UdpClient^ u )
{
   // Get the number of bytes available for reading.
   Console::WriteLine(  "Available value is {0}", u->Available );
}
public static void GetAvailable(UdpClient u)
{
    // Get the number of bytes available for reading.
    Console.WriteLine("Available value is {0}",
        u.Available);
}

備註

Available屬性是用來判斷在網路緩衝區中排入佇列以供讀取的資料量。The Available property is used to determine the amount of data queued in the network buffer for reading. 如果有可用的資料, Read請呼叫來取得資料。If data is available, call Read to get the data. 如果沒有可用的Available資料, 屬性會傳回0。If no data is available, the Available property returns 0.

如果遠端主機關閉或關閉連接, Available屬性SocketException會擲回。If the remote host shuts down or closes the connection, the Available property throws a SocketException.

注意

如果您收到SocketException, 請使用SocketException.ErrorCode來取得特定的錯誤碼, 並參閱Windows socket 第2版 API 錯誤碼檔, 以取得錯誤的詳細描述。If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code and refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

適用於