Socket.LingerState 속성

정의

보류 중인 데이터를 모두 보내려고 할 때 Socket에서 소켓 닫기를 지연할지 여부를 지정하는 값을 가져오거나 설정합니다.

public:
 property System::Net::Sockets::LingerOption ^ LingerState { System::Net::Sockets::LingerOption ^ get(); void set(System::Net::Sockets::LingerOption ^ value); };
public System.Net.Sockets.LingerOption? LingerState { get; set; }
public System.Net.Sockets.LingerOption LingerState { get; set; }
member this.LingerState : System.Net.Sockets.LingerOption with get, set
Public Property LingerState As LingerOption

속성 값

소켓을 닫는 동안 링거하는 방법을 지정하는 LingerOption입니다.

예외

소켓에 액세스하는 동안 오류가 발생했습니다.

Socket이 닫혔습니다.

예제

다음 코드 예제에서는 LingerState 속성입니다.

static void ConfigureTcpSocket(Socket^ tcpSocket)
{
     
    // Don't allow another socket to bind to this port.
    tcpSocket->ExclusiveAddressUse = true;
     
    // The socket will linger for 10 seconds after
    // Socket.Close is called.
    tcpSocket->LingerState = gcnew LingerOption(true, 10);
     
    // Disable the Nagle Algorithm for this tcp socket.
    tcpSocket->NoDelay = true;
     
    // Set the receive buffer size to 8k
    tcpSocket->ReceiveBufferSize = 8192;
     
    // Set the timeout for synchronous receive methods to
    // 1 second (1000 milliseconds.)
    tcpSocket->ReceiveTimeout = 1000;
     
    // Set the send buffer size to 8k.
    tcpSocket->SendBufferSize = 8192;
     
    // Set the timeout for synchronous send methods
    // to 1 second (1000 milliseconds.)
    tcpSocket->SendTimeout = 1000;
     
    // Set the Time To Live (TTL) to 42 router hops.
    tcpSocket->Ttl = 42;
    Console::WriteLine("Tcp Socket configured:");
    Console::WriteLine("  ExclusiveAddressUse {0}", 
        tcpSocket->ExclusiveAddressUse);
    Console::WriteLine("  LingerState {0}, {1}", 
        tcpSocket->LingerState->Enabled,
        tcpSocket->LingerState->LingerTime);
    Console::WriteLine("  NoDelay {0}",
        tcpSocket->NoDelay);
    Console::WriteLine("  ReceiveBufferSize {0}", 
        tcpSocket->ReceiveBufferSize);
    Console::WriteLine("  ReceiveTimeout {0}",
        tcpSocket->ReceiveTimeout);
    Console::WriteLine("  SendBufferSize {0}",
        tcpSocket->SendBufferSize);
    Console::WriteLine("  SendTimeout {0}",
        tcpSocket->SendTimeout);
    Console::WriteLine("  Ttl {0}",
        tcpSocket->Ttl);
    Console::WriteLine("  IsBound {0}",
        tcpSocket->IsBound);
    Console::WriteLine("");
}
static void ConfigureTcpSocket(Socket tcpSocket)
{
    // Don't allow another socket to bind to this port.
    tcpSocket.ExclusiveAddressUse = true;

    // The socket will linger for 10 seconds after
    // Socket.Close is called.
    tcpSocket.LingerState = new LingerOption (true, 10);

    // Disable the Nagle Algorithm for this tcp socket.
    tcpSocket.NoDelay = true;

    // Set the receive buffer size to 8k
    tcpSocket.ReceiveBufferSize = 8192;

    // Set the timeout for synchronous receive methods to
    // 1 second (1000 milliseconds.)
    tcpSocket.ReceiveTimeout = 1000;

    // Set the send buffer size to 8k.
    tcpSocket.SendBufferSize = 8192;

    // Set the timeout for synchronous send methods
    // to 1 second (1000 milliseconds.)
    tcpSocket.SendTimeout = 1000;

    // Set the Time To Live (TTL) to 42 router hops.
    tcpSocket.Ttl = 42;

    Console.WriteLine("Tcp Socket configured:");

    Console.WriteLine($"  ExclusiveAddressUse {tcpSocket.ExclusiveAddressUse}");

    Console.WriteLine($"  LingerState {tcpSocket.LingerState.Enabled}, {tcpSocket.LingerState.LingerTime}");

    Console.WriteLine($"  NoDelay {tcpSocket.NoDelay}");

    Console.WriteLine($"  ReceiveBufferSize {tcpSocket.ReceiveBufferSize}");

    Console.WriteLine($"  ReceiveTimeout {tcpSocket.ReceiveTimeout}");

    Console.WriteLine($"  SendBufferSize {tcpSocket.SendBufferSize}");

    Console.WriteLine($"  SendTimeout {tcpSocket.SendTimeout}");

    Console.WriteLine($"  Ttl {tcpSocket.Ttl}");

    Console.WriteLine($"  IsBound {tcpSocket.IsBound}");

    Console.WriteLine("");
}

설명

속성은 LingerState 메서드 동작 방식을 Close 변경합니다. 설정 시 이 속성은 Winsock에서 연결을 다시 설정할 수 있는 조건을 수정합니다. 연결 재설정은 IP 프로토콜 동작에 따라 계속 발생할 수 있습니다.

이 속성은 데이터를 전송할 때 에 대한 호출 Close 후 연결 지향 연결이 열린 상태로 유지되는 시간을 제어합니다.

메서드를 호출하여 피어에 데이터를 보낼 때 이 데이터는 나가는 네트워크 버퍼에 배치됩니다. 이 속성을 사용하여 메서드가 연결을 끊기 전에 이 데이터를 원격 호스트로 Close 보낼 수 있습니다.

느린 사용하려면 원하는 값이 포함된 instance 만들고 LingerOption 속성을 이 instance 설정합니다LingerState.

다음 표에서는 속성 및 속성에 Close 저장된 속성의 가능한 값에 EnabledLingerTime 대한 메서드의 동작을 LingerState 설명합니다.

LingerState.Enabled LingerState.LingerTime 동작
false (사용 안 함), 기본값 시간 제한은 적용할 수 없습니다(기본값). 기본 IP 프로토콜 제한 시간이 만료될 때까지 보류 중인 데이터를 보내려고 시도합니다.
true (사용) 0이 아닌 시간 제한 지정된 제한 시간이 만료될 때까지 보류 중인 데이터를 보내려고 시도하고 시도가 실패하면 Winsock이 연결을 다시 설정합니다.
true (사용) 시간 제한이 0입니다. 보류 중인 데이터를 모두 삭제합니다. 예를 들어 TCP(연결 지향 소켓)의 경우 Winsock은 연결을 다시 설정합니다.

IP 스택은 연결 왕복 시간에 따라 사용할 기본 IP 프로토콜 제한 시간을 계산합니다. 대부분의 경우에서 시간 제한이 스택에 의해 계산 애플리케이션에 의해 정의 된 보다 상대적입니다. 속성이 설정되지 않은 경우 소켓의 LingerState 기본 동작입니다.

속성에 LingerTimeLingerState 저장된 속성이 기본 IP 프로토콜 제한 시간보다 크게 설정되면 기본 IP 프로토콜 제한 시간이 계속 적용되고 재정의됩니다.

적용 대상