public void SendDiscoveryReply(RobeatsDevice device) { //Check if reply is an actual discovery reply if (device.StateProtocol.ProtocolType == ProtocolRequest.DeviceDiscovery) { var stateProtocolReply = new StateProtocol(ProtocolRequest.DeviceDiscoveryReply, device.Name, device.Id); var bytesReply = stateProtocolReply.ToBytes(); var clientReply = new UdpClient(AddressFamily.InterNetwork) { Ttl = 2 }; Debug.WriteLine($"Sending DR: {device.EndPoint}"); clientReply.Send(bytesReply, bytesReply.Length, (IPEndPoint)device.EndPoint); clientReply.Close(); } else { Debug.WriteLine("Not a discoveryRequest. ignoring"); } }
/// <summary> /// Send a request to a specific <see cref="IPEndPoint"/> /// </summary> /// <param name="requestType"></param> /// <param name="robeatsDevice"></param> public void SendRequest(ProtocolRequest requestType, RobeatsDevice robeatsDevice) { if (!Visible) { return; } UdpHelper udpHelper; if (requestType == ProtocolRequest.DeviceDiscovery) { udpHelper = new UdpHelper(MulticastEndPoint); } else { var ipEndPoint = new IPEndPoint(((IPEndPoint)robeatsDevice.EndPoint).Address, 4568); udpHelper = new UdpHelper(ipEndPoint); } var stateProtocol = new StateProtocol(requestType, robeatsDevice.Name, robeatsDevice.Id); Debug.WriteLine("Sending request of type: " + requestType); udpHelper.Send(stateProtocol.ToBytes()); udpHelper.Close(); }