Ejemplo n.º 1
0
 public FormConn_TcpCli(TcpCliImpl cliConn)
 {
     InitializeComponent();
     conn              = cliConn;
     RemoteIP.Text     = ((System.Net.IPEndPoint)conn.ClientSession.ClientSocket.RemoteEndPoint).Address.ToString();
     RemotePort.Text   = ((System.Net.IPEndPoint)conn.ClientSession.ClientSocket.RemoteEndPoint).Port.ToString();
     this.btnConn.Text = "断开";
 }
Ejemplo n.º 2
0
 private void btnConn_Click(object sender, EventArgs e)
 {
     if (this.btnConn.Text == "断开")
     {
         try
         {
             HandleRst rst = conn.OnStop();
             conn.Dispose();
             conn = null;
         }
         catch (Exception)
         {
             throw;
         }
         btnConn.Text = "连接";
     }
     else
     {
         string strIP = RemoteIP.Text.Trim();
         try
         {
             IPAddress ip = IPAddress.Parse(strIP);
         }
         catch (Exception)
         {
             MessageBox.Show("IP格式有错误,请重新输入!");
             return;
         }
         int port = 0;
         try
         {
             bool bflag = int.TryParse(RemotePort.Text.Trim(), out port);
             if (!bflag)
             {
                 MessageBox.Show("端口输入有错误,请重新输入!");
                 return;
             }
         }
         catch (Exception)
         {
             MessageBox.Show("端口输入有错误,请重新输入!");
             return;
         }
         conn = new TcpCliImpl(strIP, port);
         this.DialogResult = DialogResult.OK;
     }
 }