Пример #1
0
        private void 解密界面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormReceive re = new FormReceive();

            re.Show();
        }
Пример #2
0
        Socket ClientSocket;  // 套接字声明
        // 接受并创建文件
        public void Create()
        {
            Socket client = ClientSocket;  // 获得客户端套接字
            //获得客户端节点对象
            IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;

            //获得[文件名]
            string SendFileName = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client));

            // 根据时间生成文件名
            SendFileName = System.DateTime.Now.ToString("yyyyMMddhhmmss") + SendFileName.Substring(SendFileName.IndexOf('.'));

            //获得[包的大小]
            string bagSize = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client));

            //获得[包的总数量]
            int bagCount = int.Parse(System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client)));

            //获得[最后一个包的大小]
            string bagLast = System.Text.Encoding.Unicode.GetString(TransferFiles.ReceiveVarData(client));


            //创建一个新文件
            FileStream MyFileStream = new FileStream(SendFileName, FileMode.Create, FileAccess.Write);

            //已发送包的个数
            int SendedCount = 0;

            while (true)
            {
                byte[] data = TransferFiles.ReceiveVarData(client);
                if (data.Length == 0)
                {
                    break;
                }
                else
                {
                    SendedCount++;
                    //将接收到的数据包写入到文件流对象
                    MyFileStream.Write(data, 0, data.Length);
                    //显示已发送包的个数
                }
            }
            //关闭文件流
            MyFileStream.Close();
            string ip = IPAddress.Parse(((IPEndPoint)client.RemoteEndPoint).Address.ToString()).ToString();

            //关闭套接字
            client.Close();
            //文件路径
            string filepath = Application.StartupPath.ToString() + "\\" + SendFileName;

            this.Invoke((EventHandler)(delegate
            {
                if (MessageBox.Show("收到来自" + ip + "的图片,保存路径为:" + filepath + "\r\n是否打开?", "提醒", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    FormReceive re = new FormReceive();
                    re.path = filepath;
                    re.Show();
                }
            }));
        }