protected virtual string GetIpAddress(IZeroconfHost host) { var port = host.Services[SmbDomain].Port; return((host.IPAddresses.FirstOrDefault(ip => IPAddress.Parse(ip).AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) ?? host.DisplayName.ToLowerInvariant()) + ":" + port); }
private Receiver CreateReceiver(IZeroconfHost host) { //var service2 = host.Services.Keys[PROTOCOL]; //Dictionary<string, IService> service2 = host.Services.Values.First(); //string properties = service.Properties.First(); //var service2 = host.Services.Keys[PROTOCOL]; var serviceFound = host.Services.Values.First(); //IService serviceFound = null; //foreach (IService service in host.Services.Values) //{ // if (service.Name == PROTOCOL) serviceFound = service; //} //if (serviceFound == null) return null; var properties = serviceFound.Properties.First(); return(new Receiver() { Id = properties["id"], FriendlyName = properties["fn"], IPEndPoint = new IPEndPoint(IPAddress.Parse(host.IPAddress), serviceFound.Port) }); }
private void ServiceDiscoveryAirplayServiceFound(IZeroconfHost item) { //Checks if the device aldready is on the list if (airplayDevices.Count(x => x.IpAddress == item.IPAddress.ToString()) == 0) { airplayDevices.Add(new AirplayDevice(item.IPAddress, item.DisplayName)); } }
public static int GetZeroconfigHostIp(IZeroconfHost host) { var port = host.Services.First().Value.Properties.First().First(x => x.Key == PortKeyDisplayName); var intPort = int.Parse(port.Value); return(intPort); }
public async Task ConnectToServer(IZeroconfHost serverHost) { var port = serverHost.Services.First().Value.Properties.First().First(x => x.Key == "port"); var ip = IPAddress.Parse(serverHost.IPAddress); //var endpoint = new IPEndPoint(IPAddress.Loopback, 9127); Task.Run(() => { while (true) { lock (clientLock) { if (client == null || !client.Connected) { client = new TcpClient(); client.Connect(ip, 9125); } var stream = client.GetStream(); if (stream.CanWrite) { var writer = new StreamWriter(stream); writer.WriteLine("Thread 1"); writer.Flush(); writer.Close(); } Thread.Sleep(300); } } }); Task.Run(() => { while (true) { lock (clientLock) { if (client == null || !client.Connected) { client = new TcpClient(); client.Connect(ip, 9125); } var stream = client.GetStream(); if (stream.CanWrite) { var writer = new StreamWriter(stream); writer.WriteLine("Thread 2"); writer.Flush(); writer.Close(); } Thread.Sleep(300); } } }); }
public async static Task <ServerInfo> FindServerAsync(TimeSpan timeout, CancellationToken token) { string guid; CancellationTokenSource serverFoundSource; IZeroconfHost server = null; ServerInfo serverInfo; Settings.GetGuid(out guid); serverFoundSource = new CancellationTokenSource(); using (CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token, serverFoundSource.Token)) { try { #if __ANDROID__ RemoteScreen.Droid.MainActivity.mlock.Acquire(); #endif await ZeroconfResolver.ResolveAsync("_secalot._tcp.local.", scanTime : timeout, retries : 1, callback : dev => { if (dev.DisplayName == guid) { server = dev; serverFoundSource.Cancel(); } }, cancellationToken : linkedCts.Token); } catch (OperationCanceledException) { if (serverFoundSource.Token.IsCancellationRequested) { } else if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } } #if __ANDROID__ finally { RemoteScreen.Droid.MainActivity.mlock.Release(); } #endif } if (server != null) { serverInfo.ip = server.Id; serverInfo.port = server.Services["_secalot._tcp.local."].Port; return(serverInfo); } else { throw new Exception("Server not found"); } }
public ServiceAnnouncement(AdapterInformation adapterInformation, IZeroconfHost host) { if (host == null) { throw new ArgumentNullException(nameof(host)); } AdapterInformation = adapterInformation; Host = host; }
public static async Task ProbeForRTSP() { //IReadOnlyList<IZeroconfHost> results = while (Application.OpenForms.Count > 0) { IZeroconfHost host = await ZeroconfResolver.ResolveContinuous("rtsp._udp"); } }
private void NotifyDeviceFound(IZeroconfHost device) { if (device != null) { Debug.WriteLine((++deviceCount).ToString() + " - " + device.DisplayName + " : " + device.IPAddress); //Debug.WriteLine((++deviceCount).ToString() + " - " + device); } else Debug.WriteLine("Scan complete!!!!"); }
private Receiver CreateReceiver(IZeroconfHost host) { var service = host.Services[PROTOCOL]; return(new Receiver() { FriendlyName = service.Properties[0]["fn"], IPEndPoint = new IPEndPoint(IPAddress.Parse(host.IPAddress), service.Port) }); }
private static Device CreateDevice(IZeroconfHost host, string name) { Device device = new Device(); device.Ip = host.IPAddress; device.DisplayName = name; device.Type = DeviceType.Shelly; return(device); }
private IpAddress IsMediaDisplayServer(IReadOnlyList <IZeroconfHost> searchResults) { IZeroconfHost host = searchResults.FirstOrDefault(r => r.DisplayName == SERVER_NAME); if (host != null) { return(IpAddress.TryParse(String.Format("{0}:{1}", host.IPAddress, host.Services["_mediadisplay._tcp.local."].Port))); } return(null); }
private static Uri GetEndpoint(IZeroconfHost host) { var address = IPAddress.Parse(host.IPAddress); var port = DefaultEndpointPort; if (host.Services.TryGetValue("_musc._tcp.local.", out var service)) { port = service.Port; } return(new UriBuilder("http", address.ToString(), port).Uri); }
private static IReceiver CreateReceiver(IZeroconfHost host) { var service = host.Services[PROTOCOL]; var properties = service.Properties.First(); return(new Receiver() { Id = properties.ContainsKey("id") ? properties["id"] : string.Empty, FriendlyName = properties.ContainsKey("fn") ? properties["fn"] : string.Empty, Type = properties.ContainsKey("md") ? properties["md"] : string.Empty, Host = host.IPAddress, Port = service.Port }); }
static void Connect(IZeroconfHost host) { var services = host.Services; if (services.ContainsKey("_crt._tcp.local.")) { IService service = services["_crt._tcp.local."]; Connect(host.IPAddress, service.Port); } else { Console.WriteLine("No _crt._tcp.local. record found for host " + host.IPAddress); } }
public static string GetShellyName(IZeroconfHost host) { foreach (var service in host.Services) { foreach (var set in service.Value.Properties) { foreach (var kvp in set) { if (kvp.Key == "id" && kvp.Value.StartsWith("shelly")) { return(kvp.Value); } } } } return(null); }
public static async Task <IZeroconfHost> ResolveServerHost(int retries = 10) { IZeroconfHost host = null; while (retries > 0) { host = await InternalResolveServerHost(); if (host != null) { break; } Thread.Sleep(TimeSpan.FromMilliseconds(50)); } return(host); }
public bool Equals(IZeroconfHost other) { return(Equals(other as ZeroconfHost)); }