NetworkStream.WriteTimeout 속성

정의

데이터를 기다리는 중 쓰기 작업이 차단되는 시간을 가져오거나 설정합니다.

public:
 virtual property int WriteTimeout { int get(); void set(int value); };
public override int WriteTimeout { get; set; }
member this.WriteTimeout : int with get, set
Public Overrides Property WriteTimeout As Integer

속성 값

쓰기 작업의 제한 시간(밀리초)을 지정하는 Int32입니다. 이 시간이 경과하면 쓰기 작업이 실패합니다. 기본값인 Infinite는 쓰기 작업에 제한 시간이 없음을 나타냅니다.

예외

지정한 값이 0보다 작거나 같고 Infinite가 아닌 경우

예제

다음 코드 예제에서는 네트워크 스트림에 대한 쓰기 제한 시간을 10밀리초로 설정합니다.

#using <System.dll>
using namespace System;
using namespace System::Text;
using namespace System::Net;
using namespace System::Net::Sockets;

int main()
{
    // Create the server side connection and
    // start listening for clients.
    TcpListener^ tcpListener = gcnew TcpListener(IPAddress::Any, 11000);
    tcpListener->Start();
    Console::WriteLine("Waiting for a connection....");

    // Accept the pending client connection.
    TcpClient^ tcpClient = tcpListener->AcceptTcpClient();
    Console::WriteLine("Connection accepted.");
    // Get the stream to write the message
    // that will be sent to the client.
    NetworkStream^ networkStream = tcpClient->GetStream();
    String^ responseString = "Hello.";
    // Set the write timeout to 10 millseconds.
    networkStream->WriteTimeout = 10;
    // Convert the message to a byte array and sent it to the client.
    array<Byte>^ sendBytes = Encoding::UTF8->GetBytes(responseString);
    networkStream->Write(sendBytes, 0, sendBytes->Length);
    Console::WriteLine("Message Sent.");
    // Close the connection to the client.
    tcpClient->Close();
    // Stop listening for incoming connections
    // and close the server.
    tcpListener->Stop();

    // Dispose allocated resources.
    delete networkStream;
    delete tcpClient;
}
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace Examples.System.Net
{
    public class TCPListenerExample
    {
        public static void Main()
        {
            // Create the server side connection and
            // start listening for clients.
            TcpListener tcpListener = new TcpListener(IPAddress.Any,11000);
            tcpListener.Start();
            Console.WriteLine("Waiting for a connection....");

            // Accept the pending client connection.
            using TcpClient tcpClient = tcpListener.AcceptTcpClient();
            Console.WriteLine("Connection accepted.");
            // Get the stream to write the message
            // that will be sent to the client.
            using NetworkStream networkStream = tcpClient.GetStream();
            string responseString = "Hello.";
            // Set the write timeout to 10 millseconds.
            networkStream.WriteTimeout = 10;
            // Convert the message to a byte array and sent it to the client.
            Byte[] sendBytes = Encoding.UTF8.GetBytes(responseString);
            networkStream.Write(sendBytes, 0, sendBytes.Length);
            Console.WriteLine("Message Sent.");
            // Close the connection to the client.
            tcpClient.Close();
            // Stop listening for incoming connections
            // and close the server.
            tcpListener.Stop();
        }
    }
}

설명

이 속성에 지정된 시간 내에 쓰기 작업이 완료되지 않으면 쓰기 작업이 을 IOExceptionthrow합니다.

참고

이 속성은 메서드를 호출 Write 하여 수행되는 동기 쓰기 작업에만 영향을 줍니다. 이 속성은 또는 WriteAsync 메서드를 호출하여 수행되는 비동기 쓰기에 BeginWrite 영향을 주지 않습니다.

적용 대상