/// <summary> /// Constructs and broadcasts the OptIn packet to all devices on the network. /// </summary> /// <remarks> /// This is sent periodically once a second once StartADvertsising has been called. /// </remarks> protected void SendOptIn() { IPEndPoint localEndpoint = (IPEndPoint)nodeSocket.LocalEndPoint; TCNetOptIn offerPacket = new TCNetOptIn(); offerPacket.NodeOptions = NodeOptions.NeedAuthentication; offerPacket.NodeListenerPort = (ushort)localEndpoint.Port; offerPacket.VendorName = VendorName; offerPacket.DeviceName = DeviceName; offerPacket.DeviceVersion = DeviceVersion; offerPacket.NodeCount = 1; Broadcast(managementSocket, offerPacket); }
/// <summary> /// Processes the opt in packet being recieved via broadcast from other devices. /// </summary> /// <remarks> /// If the devices is newly discovered then the NewDeviceFound event will be fired. /// </remarks> /// <param name="endpoint">The endpoint.</param> /// <param name="optIn">The opt in packet that was recieved.</param> private void ProcessOptIn(IPEndPoint endpoint, TCNetOptIn optIn) { bool newDevice = false; TCNetDevice device; if (!devices.TryGetValue(optIn.NetworkID, out device)) { device = new TCNetDevice(); devices[optIn.NetworkID] = device; newDevice = true; } device.Endpoint = new TCNetEndPoint(endpoint.Address, optIn.NodeListenerPort, optIn.NodeID); device.VendorName = optIn.VendorName; device.DeviceName = optIn.DeviceName; device.NodeType = optIn.NodeType; if (newDevice) { Task.Run(() => RaiseNewDeviceFound(device)); } }