From ac1fe7dd14bcf9944bd7637b9b592662d8717025 Mon Sep 17 00:00:00 2001 From: zivillian Date: Fri, 22 Mar 2024 19:31:15 +0100 Subject: [PATCH] support hostname fixes #100 --- src/ism7mqtt/ISM7/Ism7Client.cs | 10 +++++----- src/ism7mqtt/Program.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ism7mqtt/ISM7/Ism7Client.cs b/src/ism7mqtt/ISM7/Ism7Client.cs index 7b113d5..4963173 100644 --- a/src/ism7mqtt/ISM7/Ism7Client.cs +++ b/src/ism7mqtt/ISM7/Ism7Client.cs @@ -22,7 +22,7 @@ namespace ism7mqtt public class Ism7Client { private readonly Func _messageHandler; - private readonly IPAddress _ipAddress; + private readonly string _host; private readonly ConcurrentDictionary _serializers = new ConcurrentDictionary(); private readonly Ism7Config _config; private readonly Pipe _pipe; @@ -37,10 +37,10 @@ public class Ism7Client public Func OnInitializationFinishedAsync { get; set; } - public Ism7Client(Func messageHandler, string parameterPath, IPAddress ipAddress) + public Ism7Client(Func messageHandler, string parameterPath, string host) { _messageHandler = messageHandler; - _ipAddress = ipAddress; + _host = host; _config = new Ism7Config(parameterPath); _pipe = new Pipe(); } @@ -60,7 +60,7 @@ public async Task RunAsync(string password, CancellationToken cancellationToken) private async Task ConnectAsync(CancellationToken cancellationToken) { var tcp = new TcpClient(); - await tcp.ConnectAsync(_ipAddress, 9092, cancellationToken); + await tcp.ConnectAsync(_host, 9092, cancellationToken); var certificate = new X509Certificate2(Resources.client); var ssl = new SslStream(tcp.GetStream(), false, (a, b, c, d) => true); @@ -274,7 +274,7 @@ private async Task OnPushResponseAsync(IResponse response, CancellationToken can private async Task LoadInitialValuesAsync(CancellationToken cancellationToken) { - foreach (var busAddress in _config.AddAllDevices(_ipAddress.ToString())) + foreach (var busAddress in _config.AddAllDevices(_host)) { var infoReads = _config.GetInfoReadForDevice(busAddress).ToList(); var bundleId = NextBundleId(); diff --git a/src/ism7mqtt/Program.cs b/src/ism7mqtt/Program.cs index 6c576e0..5530760 100644 --- a/src/ism7mqtt/Program.cs +++ b/src/ism7mqtt/Program.cs @@ -122,7 +122,7 @@ static async Task Main(string[] args) await mqttClient.ConnectAsync(mqttOptions, cts.Token); await mqttClient.SubscribeAsync($"Wolf/{ip}/+/set"); await mqttClient.SubscribeAsync($"Wolf/{ip}/+/set/#"); - var client = new Ism7Client((config, token) => OnMessage(mqttClient, config, enableDebug, token), parameter, IPAddress.Parse(ip)) + var client = new Ism7Client((config, token) => OnMessage(mqttClient, config, enableDebug, token), parameter, ip) { Interval = interval, EnableDebug = enableDebug