From ed7c150cc5ebdae4305d312dc2f4cfe2347d431d Mon Sep 17 00:00:00 2001 From: Christian <6939810+chkr1011@users.noreply.github.com> Date: Tue, 19 Jul 2022 20:47:16 +0200 Subject: [PATCH] Add new options. --- Source/MQTTnet/Client/Options/MqttClientTcpOptions.cs | 7 +++++++ Source/MQTTnet/Implementations/MqttTcpChannel.cs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/Source/MQTTnet/Client/Options/MqttClientTcpOptions.cs b/Source/MQTTnet/Client/Options/MqttClientTcpOptions.cs index 479bb1c5..879d8ac7 100644 --- a/Source/MQTTnet/Client/Options/MqttClientTcpOptions.cs +++ b/Source/MQTTnet/Client/Options/MqttClientTcpOptions.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Net; using System.Net.Sockets; namespace MQTTnet.Client @@ -10,6 +11,12 @@ namespace MQTTnet.Client { public AddressFamily AddressFamily { get; set; } = AddressFamily.Unspecified; + /// + /// Gets the local endpoint (network card) which is used by the client. + /// Set it to _null_ to let the OS select the network card. + /// + public EndPoint LocalEndpoint { get; set; } + public int BufferSize { get; set; } = 8192; public bool? DualMode { get; set; } diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.cs index 295cee6b..f1391bc1 100644 --- a/Source/MQTTnet/Implementations/MqttTcpChannel.cs +++ b/Source/MQTTnet/Implementations/MqttTcpChannel.cs @@ -68,6 +68,11 @@ namespace MQTTnet.Implementations socket = new CrossPlatformSocket(_tcpOptions.AddressFamily); } + if (_tcpOptions.LocalEndpoint != null) + { + socket.Bind(_tcpOptions.LocalEndpoint); + } + socket.ReceiveBufferSize = _tcpOptions.BufferSize; socket.SendBufferSize = _tcpOptions.BufferSize; socket.SendTimeout = (int)_clientOptions.Timeout.TotalMilliseconds;