İngilizce dilinde oku

Aracılığıyla paylaş


Socket.SendTimeout Özellik

Tanım

Zaman uyumlu Send çağrının zaman aşımına uyacağını belirten bir değer alır veya ayarlar.

C#
public int SendTimeout { get; set; }

Özellik Değeri

Milisaniye cinsinden zaman aşımı değeri. Özelliğini 1 ile 499 arasında bir değerle ayarlarsanız, değer 500 olarak değiştirilir. Varsayılan değer 0'dır ve bu da sonsuz zaman aşımı süresini gösterir. -1 değerinin belirtilmesi de sonsuz bir zaman aşımı süresini gösterir.

Özel durumlar

Yuvaya erişmeye çalışılırken bir hata oluştu.

Bir küme işlemi için belirtilen değer -1'den küçük.

Örnekler

Aşağıdaki kod örneği özelliğinin SendTimeout kullanımını gösterir.

C#
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("");
}

Açıklamalar

Bu seçenek yalnızca zaman uyumlu Send çağrılar için geçerlidir. Zaman aşımı süresi aşılırsa yöntemi Send bir SocketExceptionoluşturur.

Şunlara uygulanır

Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1