public static bool ReceiveFileFrom(byte[] metadataAsBytes, UdpClient sender)
        {
            FileMetadata meta = new FileMetadata(metadataAsBytes);
            byte[] receivedBytes = null;
            IPEndPoint remoteIPEndPoint = null;
            int currentPacket = 0;
            if (File.Exists(Encoding.Default.GetString(meta.filename))) {
                bool success = false;
                while (!success) {
                    try {
                        File.Delete(Encoding.Default.GetString(meta.filename));
                        success = true;
                    }
                    catch (IOException ex) {
                        return false;
                    }
                    catch (Exception ex) {
                        return false;
                    }
                }
            }
            while (currentPacket < meta.totalPackets) {
                receivedBytes = sender.Receive(ref remoteIPEndPoint);
                if (Utils.VerifyChecksum(receivedBytes)) {
                    if (receivedBytes[Constants.FIELD_TYPE] == Constants.TYPE_FILE_DELIVERY) {
                        SendAckTo(-1, sender);
                        return false;
                    }
                    Data datapack = new Data(receivedBytes);

                    if (datapack.id < meta.totalPackets - 1 && datapack.id == currentPacket) {
                        bool success = false;
                        while (!success) {
                            try {
                                File.AppendAllText(Encoding.Default.GetString(meta.filename), Encoding.Default.GetString(datapack.payload), Encoding.Default);
                                success = true;
                            }
                            catch (Exception e) {
                                Console.WriteLine(e.Message);
                            }
                        }

                        currentPacket++;
                        SendAckTo(datapack.id, sender);
                    }
                    else if (datapack.id == meta.totalPackets - 1 && datapack.id == currentPacket) {
                        int remainder = (meta.fileLength % Constants.PAYLOAD_SIZE);
                        byte[] finalBytes = new byte[remainder];
                        for (int i = 0; i < remainder; i++) {
                            finalBytes[i] = receivedBytes[i + Constants.FIELD_PAYLOAD];
                        }
                        File.AppendAllText(Encoding.Default.GetString(meta.filename), Encoding.Default.GetString(finalBytes), Encoding.Default);

                        currentPacket++;
                        SendAckTo(datapack.id, sender);
                    }
                    else if (datapack.id < currentPacket) {
                        SendAckTo(datapack.id, sender);
                    }
                }
            }
            return true;
        }
        public static bool ReceiveAllDirectoryPackets(byte[] first, DirMetadata meta, UdpClient target)
        {
            IPEndPoint remoteIPEndPoint = null;
            if (first == null) { return false; }
            Data data = new Data(first);

            if (meta.dirLength < Constants.PAYLOAD_SIZE)
                Console.WriteLine(Encoding.Default.GetString(data.payload,0,meta.dirLength));
            else
                Console.WriteLine(Encoding.Default.GetString(data.payload));

            SendAckTo(data.id, target);
            int currentPacket = 1;
            while (currentPacket < meta.totalPackets) {
                byte[] recBytes = target.Receive(ref remoteIPEndPoint);
                if (!Utils.VerifyChecksum(recBytes)) {
                    continue;
                }
                data = new Data(recBytes);
                if (data.id < currentPacket) {
                    SendAckTo(data.id, target);
                }
                else if (data.id == currentPacket && currentPacket != meta.totalPackets - 1) {
                    Console.WriteLine(Encoding.Default.GetString(data.payload));
                    SendAckTo(data.id, target);
                    currentPacket++;
                }
                else if (data.id == currentPacket && currentPacket == meta.totalPackets - 1) {

                    byte[] finalBytes = new byte[(meta.dirLength % Constants.PAYLOAD_SIZE)];
                    for (int i = 0; i < finalBytes.Length; i++) {
                        finalBytes[i] = data.payload[i + Constants.FIELD_PAYLOAD];
                    }
                    Console.WriteLine(Encoding.Default.GetString(finalBytes));
                    currentPacket++;

                    SendAckTo(data.id, target);
                }
            }
            return true;
        }