Ejemplo n.º 1
0
        private void FileSendThreRun()
        {
            int n = 1;

            foreach (string f in FileList)
            {
                Flag = true;
                FileInfo fi = new FileInfo(f);
                filename = fi.Name;
                string date = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                fs = new FileStream(f, FileMode.Open, FileAccess.Read);
                byte[] buf = new byte[fs.Length];
                fs.Read(buf, 0, buf.Length);
                fs.Close();
                mook_Packet.Packet mypacket = new mook_Packet.Packet(filename, buf.Length, buf, date);
                client = new TcpClient();
                client.Connect(ip, port);
                ns       = client.GetStream();
                myRead   = new StreamReader(ns);
                myReader = new Thread(Receive);
                myReader.Start();

                BinaryWriter writer = new BinaryWriter(ns);
                byte[]       data   = ObjectToBytes(mypacket);
                writer.Write(data.Length);
                writer.Write(data);
                Invoke(OnCount, n);
                while (true)
                {
                    if (!Flag)
                    {
                        break;
                    }
                    Thread.Sleep(1);
                }
                n++;
            }
        }
Ejemplo n.º 2
0
        private void AcceptFile()
        {
            while (true)
            {
                try
                {
                    servClient = server.AcceptTcpClient();
                    ns         = servClient.GetStream();
                    myWrite    = new StreamWriter(ns);
                    reader     = new BinaryReader(ns);
                    int                length   = reader.ReadInt32();
                    byte[]             packet   = reader.ReadBytes(length);
                    mook_Packet.Packet mypacket = BytesToObject(packet);

                    FileStream fs = new FileStream(Application.StartupPath + @"\File\" + mypacket.FileName, FileMode.Create);
                    fs.Write(mypacket.Data, 0, mypacket.Size);
                    fs.Close();
                    Invoke(OnFile, mypacket.Date, mypacket.FileName);
                    myWrite.WriteLine(mypacket.FileName);
                    myWrite.Flush();
                }
                catch { }
            }
        }