public void Dispose() { if (ClientSocket != null) { ClientSocket.StopListeningAsync().Wait(); ClientSocket.Dispose(); ClientSocket = null; } }
private async Task SendDiscoveryPacketAsync() { var ports = Network.GetAvailablePort(1000, Networks.Count); if (ports.Count == 0 || ports.Count < Networks.Count) { HelperMy.Notification(Color.Red, "Kullanılabilir port bulunamadığı için işlem iptal edildi."); await ClientSocket.StopListeningAsync(); ClientSocket.Dispose(); ClientSocket = null; return; } for (int i = 0; i < Networks.Count; i++) { var item = Networks[i]; var data = PacketGenerator.GenerateDiscoveryPacket(item.LocalIPAddress, (short)ports[i]); await ClientSocket.SendToAsync(data, new IPEndPoint(item.BroadcastIPAddress, 80)); } }