diff --git a/VrcOscIntegrations/Services/OscActions.cs b/VrcOscIntegrations/Services/OscActions.cs index 871baec..22d5280 100644 --- a/VrcOscIntegrations/Services/OscActions.cs +++ b/VrcOscIntegrations/Services/OscActions.cs @@ -96,19 +96,29 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _sender = new UdpClient(); + List tasks = new List() + { + Runner1() + }; + _senderEndpoint = new IPEndPoint(IPAddress.Parse(MainConfig.Instance.OscClient.IpAddress), MainConfig.Instance.OscClient.Port); Logger.Info("OscSender", $"Connect to IP: {MainConfig.Instance.OscClient.IpAddress}, Port: {MainConfig.Instance.OscClient.Port}.", Color.Yellow, Color.White); _sender.Connect(_senderEndpoint); - _receiverEndpoint = new IPEndPoint(IPAddress.Parse(MainConfig.Instance.OscServer.IpAddress), MainConfig.Instance.OscServer.Port); - Logger.Info("OscReceiver", $"Start listening on IP: {MainConfig.Instance.OscServer.IpAddress}, Port: 9001.", Color.Yellow, Color.White); - _receiver = new UdpClient(_receiverEndpoint); + try + { + _receiverEndpoint = new IPEndPoint(IPAddress.Parse(MainConfig.Instance.OscServer.IpAddress), MainConfig.Instance.OscServer.Port); + Logger.Info("OscReceiver", $"Start listening on IP: {MainConfig.Instance.OscServer.IpAddress}, Port: {MainConfig.Instance.OscServer.Port}.", Color.Yellow, Color.White); + _receiver = new UdpClient(_receiverEndpoint); - await Task.WhenAll(new Task[] + tasks.Add(Runner2()); + } + catch(Exception ex) { - Runner1(), - Runner2() - }); + Logger.Error("OscReceiver", $"Error thrown while trying to listen on port {MainConfig.Instance.OscServer.Port}, error {ex}", Color.Yellow, Color.Red); + } + + await Task.WhenAll(tasks); } private async Task Runner1()