diff --git a/QControlKit/QBrowser.cs b/QControlKit/QBrowser.cs index f03a01b..faa71cc 100644 --- a/QControlKit/QBrowser.cs +++ b/QControlKit/QBrowser.cs @@ -26,13 +26,17 @@ namespace QControlKit public async void ProbeForQLabInstances() { + Log.Debug("[qbrowser] probing for instances"); + IReadOnlyList results = await ZeroconfResolver.ResolveAsync(QBonjour.TCPService,TimeSpan.FromSeconds(3)); foreach (var zeroconfHost in results) { + Log.Debug($"[qbrowser] found host {zeroconfHost.IPAddress}:{zeroconfHost.DisplayName}"); foreach (var service in zeroconfHost.Services) { + Log.Debug($"[qbrowser] found {service.Key}:{service.Value}"); if (service.Key.Equals(QBonjour.TCPService)) { diff --git a/QControlKit/QClient.cs b/QControlKit/QClient.cs index 84cf8ea..11f9dbb 100644 --- a/QControlKit/QClient.cs +++ b/QControlKit/QClient.cs @@ -59,7 +59,7 @@ namespace QControlKit public void sendMessage(string address, params object[] args) { - tcpClient.Send(new OscMessage(address, args)); + tcpClient.QueueForSending(new OscMessage(address, args)); Log.Debug($"[client] send message {address} : {args}"); } diff --git a/QControlKit/QControlKit.csproj b/QControlKit/QControlKit.csproj index a322c60..562a1fa 100644 --- a/QControlKit/QControlKit.csproj +++ b/QControlKit/QControlKit.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.1 false Joel Wetzell 1.0.0-devel @@ -16,14 +16,18 @@ - + + + + + diff --git a/QControlKit/SharpOSC/TCPClient.cs b/QControlKit/SharpOSC/TCPClient.cs index a5b9947..23119bd 100644 --- a/QControlKit/SharpOSC/TCPClient.cs +++ b/QControlKit/SharpOSC/TCPClient.cs @@ -31,7 +31,12 @@ namespace SharpOSC } public delegate void MessageReceivedHandler(object source, MessageEventArgs args); public event MessageReceivedHandler MessageReceived; + + private Queue SendQueue = new Queue(); + private Thread receivingThread; + private Thread sendThread; + string _address; TcpClient client; @@ -54,6 +59,10 @@ namespace SharpOSC client = new TcpClient(Address, Port); receivingThread = new Thread(ReceiveLoop); receivingThread.Start(); + + sendThread = new Thread(SendLoop); + sendThread.Start(); + Log.Debug($"[tcpclient] connected to <{Address}:{Port}>"); return true; } @@ -65,6 +74,23 @@ namespace SharpOSC } + public void QueueForSending(OscPacket packet) + { + SendQueue.Enqueue(packet); + } + + private void SendLoop() + { + while (client != null && client.Connected) + { + if(SendQueue.Count > 0) + { + OscPacket packet = SendQueue.Dequeue(); + Send(packet); + } + } + } + public void Send(byte[] message) { byte[] slipData = SlipEncode(message); @@ -91,7 +117,7 @@ namespace SharpOSC public void ReceiveLoop() { - while (client.Connected) + while (client != null && client.Connected) { Receive(); } @@ -124,10 +150,11 @@ namespace SharpOSC } while (netStream.DataAvailable); //Console.WriteLine("Raw TCP In: " + System.Text.Encoding.UTF8.GetString(responseData.ToArray())); - OscMessage response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray()); + OscPacket packet = OscPacket.GetPacket(responseData.Skip(1).ToArray()); + OscMessage responseMessage = (OscMessage)packet; //watch.Stop(); //Console.WriteLine($"TCPCLient - message receive took {watch.ElapsedMilliseconds}ms and {reads} reads"); - OnMessageReceived(response); + OnMessageReceived(responseMessage); } } catch(Exception e) { diff --git a/QControlKitXamDemo/QControlKitXamDemo.Android/QControlKitXamDemo.Android.csproj b/QControlKitXamDemo/QControlKitXamDemo.Android/QControlKitXamDemo.Android.csproj index f1a51fb..c0c1a3e 100644 --- a/QControlKitXamDemo/QControlKitXamDemo.Android/QControlKitXamDemo.Android.csproj +++ b/QControlKitXamDemo/QControlKitXamDemo.Android/QControlKitXamDemo.Android.csproj @@ -57,7 +57,7 @@ 0.2.0.64 - + diff --git a/QControlKitXamDemo/QControlKitXamDemo.iOS/Info.plist b/QControlKitXamDemo/QControlKitXamDemo.iOS/Info.plist index ddf62aa..b614303 100644 --- a/QControlKitXamDemo/QControlKitXamDemo.iOS/Info.plist +++ b/QControlKitXamDemo/QControlKitXamDemo.iOS/Info.plist @@ -2,37 +2,43 @@ - UIDeviceFamily - - 1 - 2 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - MinimumOSVersion - 8.0 - CFBundleDisplayName - QControlKitXamDemo - CFBundleIdentifier - com.companyname.QControlKitXamDemo - CFBundleVersion - 1.0 - UILaunchStoryboardName - LaunchScreen - CFBundleName - QControlKitXamDemo - XSAppIconAssets - Assets.xcassets/AppIcon.appiconset + UIDeviceFamily + + 1 + 2 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + MinimumOSVersion + 8.0 + CFBundleDisplayName + QControlKitXamDemo + CFBundleIdentifier + com.companyname.QControlKitXamDemo + CFBundleVersion + 1.0 + UILaunchStoryboardName + LaunchScreen + CFBundleName + QControlKitXamDemo + XSAppIconAssets + Assets.xcassets/AppIcon.appiconset + NSBonjourServices + + _qlab._tcp + + NSLocalNetworkUsageDescription + Scan network for QLab instances diff --git a/QControlKitXamDemo/QControlKitXamDemo.iOS/QControlKitXamDemo.iOS.csproj b/QControlKitXamDemo/QControlKitXamDemo.iOS/QControlKitXamDemo.iOS.csproj index 469e138..c733ff8 100644 --- a/QControlKitXamDemo/QControlKitXamDemo.iOS/QControlKitXamDemo.iOS.csproj +++ b/QControlKitXamDemo/QControlKitXamDemo.iOS/QControlKitXamDemo.iOS.csproj @@ -51,6 +51,7 @@ Entitlements.plist None -all + Wildcard none @@ -130,7 +131,7 @@ 0.2.0.64 - + diff --git a/QControlKitXamDemo/QControlKitXamDemo/MainPage.xaml.cs b/QControlKitXamDemo/QControlKitXamDemo/MainPage.xaml.cs index 80bb596..798e341 100644 --- a/QControlKitXamDemo/QControlKitXamDemo/MainPage.xaml.cs +++ b/QControlKitXamDemo/QControlKitXamDemo/MainPage.xaml.cs @@ -30,7 +30,11 @@ namespace QControlKitXamDemo { Task.Run(async () => { - browser.ProbeForQLabInstances(); + Device.BeginInvokeOnMainThread(() => + { + browser.ProbeForQLabInstances(); + }); + }); return true; }); diff --git a/QControlKitXamDemo/QControlKitXamDemo/QControlKitXamDemo.csproj b/QControlKitXamDemo/QControlKitXamDemo/QControlKitXamDemo.csproj index 5eb7271..45ca61d 100644 --- a/QControlKitXamDemo/QControlKitXamDemo/QControlKitXamDemo.csproj +++ b/QControlKitXamDemo/QControlKitXamDemo/QControlKitXamDemo.csproj @@ -12,7 +12,7 @@ - +