HttpListenerRequest.KeepAlive Właściwość

Definicja

Pobiera wartość wskazującą Boolean , czy klient żąda połączenia trwałego.

public:
 property bool KeepAlive { bool get(); };
public bool KeepAlive { get; }
member this.KeepAlive : bool
Public ReadOnly Property KeepAlive As Boolean

Wartość właściwości

true jeśli połączenie powinno być otwarte; w przeciwnym razie , false.

Przykłady

Poniższy przykład kodu pokazuje użycie tej właściwości.

public static void ShowRequestProperties2 (HttpListenerRequest request)
{
    Console.WriteLine("KeepAlive: {0}", request.KeepAlive);
    Console.WriteLine("Local end point: {0}", request.LocalEndPoint.ToString());
    Console.WriteLine("Remote end point: {0}", request.RemoteEndPoint.ToString());
    Console.WriteLine("Is local? {0}", request.IsLocal);
    Console.WriteLine("HTTP method: {0}", request.HttpMethod);
    Console.WriteLine("Protocol version: {0}", request.ProtocolVersion);
    Console.WriteLine("Is authenticated: {0}", request.IsAuthenticated);
    Console.WriteLine("Is secure: {0}", request.IsSecureConnection);
}
Public Shared Sub ShowRequestProperties2(ByVal request As HttpListenerRequest)
    Console.WriteLine("KeepAlive: {0}", request.KeepAlive)
    Console.WriteLine("Local end point: {0}", request.LocalEndPoint.ToString())
    Console.WriteLine("Remote end point: {0}", request.RemoteEndPoint.ToString())
    Console.WriteLine("Is local? {0}", request.IsLocal)
    Console.WriteLine("HTTP method: {0}", request.HttpMethod)
    Console.WriteLine("Protocol version: {0}", request.ProtocolVersion)
    Console.WriteLine("Is authenticated: {0}", request.IsAuthenticated)
    Console.WriteLine("Is secure: {0}", request.IsSecureConnection)
End Sub

Uwagi

Jeśli klient HTTP i serwer spodziewają się wielokrotnej wymiany danych w krótkim czasie, trwałe połączenie przyspiesza komunikację, umożliwiając im uniknięcie obciążenia wymaganego do otwarcia i zamknięcia połączenia TCP dla każdego komunikatu. W przypadku klientów korzystających z protokołu HTTP/1.1 wartość domyślna dla tej właściwości to true.

Dotyczy

Zobacz też