Ejemplo n.º 1
0
        /*——绘制进度条——*/
        private void Progress()
        {
            /*---  SEEK命令  ---*/
            // 计时开始
            stpwth.Start();
            while (current_progress != total_progress)
            {
                socket5656.Send(Encoding.UTF8.GetBytes("SEEK"));
                socket5656.Receive(buffer5656);

                current_progress = ConcUtilities.GetLong(buffer5656);
                double prog_in_100 = (double)current_progress / total_progress * 100;
                updateProgressBar((long)prog_in_100);
                sizeStatus.Text = String.Format("{0:F}%", prog_in_100);

                Thread.Sleep(100);//当前任务休眠0.1秒
            }
        }
Ejemplo n.º 2
0
        /*——有关9898端口全局函数定义部分:——*/
        void Communicate9898()
        {
            while (true)  //一直重复

            /* socket9898.执行
             * {Shutdown(SocketShutdown.Both);
             * socket9898.Close();*/
            {
                int r = 0;
                while ((r = socket9898.Receive(buffer9898)) == 0)
                {
                    ;
                }
                socket9898.Send(Encoding.UTF8.GetBytes("OK"));
                string s    = Encoding.UTF8.GetString(buffer9898, 0, r);
                string info = s.Substring(0, 2);
                if (info == "ER")
                {
                    string error_info = s.Substring(3, 3);
                    if (error_info == "001")
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show(this, "Could not start sending process, because the remote server address at the given port is not connectable. Errorcode: " + error_info, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (error_info == "002")
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show(this, "File or directory could not be found: ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (error_info == "003")
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show(this, "Connection failed while transferring. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (error_info == "005")
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show(this, "Client/Server status fault. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (error_info == "006")
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show(this, "Instruction was unable to send.", "ERROR 006", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (error_info == "007")
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show(this, "Bad list.send.", "ERROR 007", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    try
                    {
                        TaskCompleted();
                    }
                    catch (Exception) { };
                }
                else if (info == "CP")
                {
                    // 清洁函数
                    try
                    {
                        TaskCompleted();
                    }
                    catch (Exception) { };
                }
                else if (info == "IF")
                {
                    string tip_info = s.Substring(3, 3);
                    //extBox_Dialog.AppendText("收到了IF" + tip_info);

                    if (tip_info == "001")
                    {
                        txtDialogue.AppendText("Connection to server was established.\r\n");
                    }
                    else if (tip_info == "002")
                    {
                        /*---  TSZE命令  ---*/
                        txtDialogue.AppendText("File transfer has just started.\r\n");
                        socket5656.Send(Encoding.UTF8.GetBytes("TSZE"));
                        socket5656.Receive(buffer5656);

                        //获取总共任务量
                        total_progress = ConcUtilities.GetLong(buffer5656);
                        txtDialogue.AppendText("Task size: " + total_progress + "\r\n");

                        // 设置进度条
                        EstablishProgress();
                        // test
                        // txtDialogue.AppendText("Progress bar set done\r\n");
                    }
                    else if (tip_info == "003")
                    {
                        txtDialogue.AppendText("Transfer is over.\r\n");

                        stpwth.Stop();
                        TimeSpan ts = stpwth.Elapsed;
                        this.txtDialogue.AppendText(String.Format("Speed: {0:F} MB/s", ((double)total_progress / 1048576) / ts.TotalSeconds));
                        stpwth.Reset();

                        // 设置completed图像
                        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
                        this.imgConc.Image = (System.Drawing.Image)(resources.GetObject("imgCompleted.Image"));
                        try
                        {
                            TaskCompleted();
                        }
                        catch (Exception) { };

                        return;
                    }
                    else
                    {
                    }
                }
                else if (info == "QU")
                {
                    // socket9898.Send(Encoding.UTF8.GetBytes("OK"));
                    int    r1 = socket9898.Receive(buffer9898);
                    string s1 = Encoding.UTF8.GetString(buffer9898, 0, r1);
                    socket9898.Send(Encoding.UTF8.GetBytes("OK"));
                    int          r2     = socket9898.Receive(buffer9898);
                    string       s2     = Encoding.UTF8.GetString(buffer9898, 0, r2);
                    DialogResult result = MessageBox.Show(s2, "Tips", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        socket9898.Send(Encoding.UTF8.GetBytes("OK"));
                        return;
                    }
                    else
                    {
                        socket9898.Send(Encoding.UTF8.GetBytes("NO"));
                        return;
                    }
                }
                //txtDialogue.AppendText(socketClient.RemoteEndPoint + ":" + s + "\r\r\n");
            }
        }