Socket.ExclusiveAddressUse Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar eller anger ett värde som anger om endast Socket en process kan bindas till en port.
public:
property bool ExclusiveAddressUse { bool get(); void set(bool value); };
public bool ExclusiveAddressUse { get; set; }
member this.ExclusiveAddressUse : bool with get, set
Public Property ExclusiveAddressUse As Boolean
Egenskapsvärde
true
Socket om tillåter endast en socket att binda till en specifik port, annars , false. Standardvärdet är true för Windows Server 2003 och Windows XP och nyare versioner.
Undantag
Ett fel uppstod vid försök att komma åt socketen.
Har Socket stängts.
Bind(EndPoint) har kallats för detta Socket.
Exempel
Följande kodexempel visar hur egenskapen används ExclusiveAddressUse .
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("");
}
Kommentarer
Om ExclusiveAddressUse är falsekan flera socketar använda Bind metoden för att binda till en specifik port, men endast en av socketarna kan utföra åtgärder på nätverkstrafiken som skickas till porten. Om fler än en socket försöker använda Bind(EndPoint) metoden för att binda till en viss port hanterar den med den mer specifika IP-adressen nätverkstrafiken som skickas till den porten.
Om ExclusiveAddressUse är truelyckas den första användningen av Bind metoden för att försöka binda till en viss port, oavsett IP-adress (Internet Protocol). Alla efterföljande användningar av Bind metoden för att försöka binda till den porten misslyckas tills den ursprungliga bundna socketen har förstörts.
Den här egenskapen måste anges innan Bind anropas. Annars genereras en InvalidOperationException .