Example #1
0
        private static void StartReceiving(string ipa, string path, int send_port)
        {
            path += "\\";
            try
            {
                IPEndPoint ipadress = new IPEndPoint(IPAddress.Parse(ipa), send_port);

                if (tlsServer == null)
                {
                    tlsServer = new TcpListener(ipadress);
                }
                tlsServer.Start();
                TcpClient tclServer = tlsServer.AcceptTcpClient();
                strRemote = tclServer.GetStream();
                List <byte> Bytes = new List <byte>();
                Bytes.WholeAdding(strRemote);
                ReceivedFile Model = ConvertFileModel(Bytes.ToArray());
                NameFile = Model.FileName;
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                FileStream fs = File.Create(path + Model.FileName);
                // Byte[] info = new ASCIIEncoding().GetBytes(Model.FileContent);
                Byte[] info = Model.FileContent;
                fs.Write(info, 0, info.Length);
                fs.Close();
            }
            finally
            {
                strRemote.Close();
                //StartReceiving( ipa, path, send_port);
            }
        }
Example #2
0
        private static ReceivedFile ConvertFileModel(byte[] DBytes)
        {
            try
            {
                string       FullData = Encoding.ASCII.GetString(DBytes);
                ReceivedFile File     = new ReceivedFile();

                int FinishedIndex;
                File.FileName = GetSelected(FullData, 0, '&', out FinishedIndex);
                File.FileSize = GetSelected(FullData, FinishedIndex + 1, '&', out FinishedIndex);
                //File.FileContent = FullData.Substring(FinishedIndex + 1);
                int tt = DBytes.Length - (FinishedIndex + 1);
                DataContent = new byte[tt];
                Array.Copy(DBytes, FinishedIndex + 1, DataContent, 0, tt);
                File.FileContent = DataContent;
                return(File);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }