コード例 #1
0
ファイル: FrmMain.cs プロジェクト: ZZRRegion/HaiFu
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (this.client != null)
     {
         this.client.MsgEventHandle  -= this.Client_MsgEventHandle;
         this.client.FileEventHandle -= this.Client_FileEventHandle;
         this.client.Dispose();
         this.btnConnect.Text = "连接";
         this.client          = null;
     }
     else
     {
         try
         {
             TcpClient  client = new TcpClient();
             int        port   = (int)this.nudPort.Value;
             IPEndPoint end    = new IPEndPoint(IPAddress.Parse(this.txtIP.Text), port);
             client.Connect(end);
             if (client.Connected)
             {
                 this.btnConnect.Text = "断开";
                 this.client          = new HaiFu.Protocol.HaiFuClient(client, Guid.NewGuid().ToString("N"));
                 this.client.SavePath = this.txtPath.Text;
                 this.client.SendName(this.txtName.Text);
                 this.client.MsgEventHandle  += Client_MsgEventHandle;
                 this.client.FileEventHandle += Client_FileEventHandle;
             }
         }
         catch (Exception ex)
         {
             this.MsgBox(ex.Message);
         }
     }
 }
コード例 #2
0
ファイル: FrmMain.cs プロジェクト: ZZRRegion/HaiFu
        private void Client_MsgEventHandle(HaiFu.Protocol.HaiFuClient arg1, string arg2)
        {
            Action action = () => {
                string msg = $"{DateTime.Now}:{arg2}{Environment.NewLine}";
                this.AppendText(msg);
            };

            this.Invoke(action);
        }
コード例 #3
0
ファイル: FrmMain.cs プロジェクト: ZZRRegion/HaiFu
        private void Client_FileEventHandle(HaiFu.Protocol.HaiFuClient arg1, string arg2, int progress)
        {
            Action action = () => {
                string msg = $"[{arg2}], {progress}{Environment.NewLine}";
                this.AppendText(msg);
            };

            this.Invoke(action);
        }