private void OnMessageReceivedFromMulticastGroup(object sender, MessegeReceviedEventArgs args) { if (args.Payload.MessageTypeName == typeof(DiscoveryRequestMessage).Name) { _discoveryRequestMessage = (DiscoveryRequestMessage)args.Payload; _serverNode.GetDataQuantity(); } if (args.Payload.MessageTypeName == typeof(ConnectTheGraphMessage).Name) { _serverNode.ConnectoToKnowServers(); Console.WriteLine("Server graph connected !"); } }
public override async void Discover() { if (debug) { Debug.WriteLine("Discovery System: Sending Discovery Request"); } try { // Get an output stream to all IPs on the given port using (var stream = await socket.GetOutputStreamAsync(new HostName("255.255.255.255"), udpPort.ToString())) { // Get a data writing stream using (var writer = new DataWriter(stream)) { // Include all known devices in the request to minimize traffic (smart devices can use this info to determine if they need to respond) JArray jDevices = new JArray(); foreach (var device in Devices) { JObject jDevice = new JObject(); jDevice.Add("deviceInfo", device.DeviceInfo); jDevice.Add("name", device.Name); jDevices.Add(jDevice); } // Create a discovery request message DiscoveryRequestMessage discoveryRequestMessage = new DiscoveryRequestMessage("DISCOVER", name, IpAddress, jDevices); // Convert the request to a JSON string writer.WriteString(JsonConvert.SerializeObject(discoveryRequestMessage)); if (debug) { Debug.WriteLine($" >>> {JsonConvert.SerializeObject(discoveryRequestMessage)}"); } // Send await writer.StoreAsync(); } } } catch (Exception ex) { Debug.WriteLine("Discovery System Server - Send Discovery Request Failed: " + ex.Message); } }
public override void Discover() { if (debug) { Debug.WriteLine("Discovery System: Sending Discovery Request"); } try { // Include all known devices in the request to minimize traffic (smart devices can use this info to determine if they need to respond) JArray jDevices = new JArray(); foreach (var device in Devices) { JObject jDevice = new JObject(); jDevice.Add("deviceInfo", device.DeviceInfo); jDevice.Add("name", device.Name); jDevices.Add(jDevice); } // Create a discovery request message DiscoveryRequestMessage discoveryRequestMessage = new DiscoveryRequestMessage("DISCOVER", name, IpAddress, jDevices); var requestString = JsonConvert.SerializeObject(discoveryRequestMessage); var bytes = Encoding.ASCII.GetBytes(requestString); if (debug) { Debug.WriteLine($" >>> {requestString}"); } socket.Send(bytes, bytes.Length); } catch (Exception ex) { Debug.WriteLine("Discovery System Server - Send Discovery Request Failed: " + ex.Message); } }
private void SendDicoveryRequest(DiscoveryRequestMessage discoveryRequestMessage) { _discoveryBuss.Direct(discoveryRequestMessage, _config.DiscoveryRequestsQueueName); }