Exemplo n.º 1
0
 private void CloseNetWork()
 {
     if (client != null && client.Connected)
     {
         client.Close();
         client.Dispose();
     }
 }
Exemplo n.º 2
0
 public void OnDisconnect(object sender, EventArgs e)
 {
     m_TcpClient.Close();
     if (m_HeartBeadCoroutine != null)
     {
         m_HeartBeat = false;
     }
 }
Exemplo n.º 3
0
 // 界面关闭时,关闭相应未断开的连接
 private void ControlFrm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (tcpClient.Connected)
     {
         devMonitor.StopMonitor();
         // 关闭当前连接
         tcpClient.Close();
     }
 }
Exemplo n.º 4
0
 private void disconnectBtn_Click(object sender, EventArgs e)
 {
     if (isConnect)
     {
         client.Close();   /*关闭连接*/
         client.Dispose(); /*释放资源*/
         isConnect = false;
         receiveTb.AppendText(Line++ + "  已与服务器断开:" + "\n");
         connectBtn.Text = "重连";
     }
     else
     {
         MessageBox.Show("未创建连接,请先创建连接");
         ipTb.Focus();
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 关闭连接
 /// </summary>
 public void Close()
 {
     if (client != null)
     {
         doCloseSocket = true;
         client.Close();
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 断开连接
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DisconnectClicked(object sender, RoutedEventArgs e)
 {
     if (tcpClient != null)
     {
         tcpClient.DatagramReceived -= client_DatagramReceived;
         tcpClient.Close();
     }
 }
Exemplo n.º 7
0
        private void connectBtn_Click(object sender, EventArgs e)
        {
            bool blnText1 = false;//检查端口是否合法

            blnText1 = IsNumberic(portTb.Text);
            //连接服务端
            if (this.IsPort() && blnText1)
            {
                String ip   = ipTb.Text;
                int    port = Convert.ToInt32(portTb.Text);
                client = new AsyncTcpClient(new IPEndPoint(IPAddress.Parse(ip), port));
                client.ServerDisconnected += new EventHandler <TcpServerDisconnectedEventArgs>(client_ServerDisconnected);
                client.PlaintextReceived  += new EventHandler <TcpDatagramReceivedEventArgs <string> >(client_PlaintextReceived);
                client.ServerConnected    += new EventHandler <TcpServerConnectedEventArgs>(client_ServerConnected);
                if (connectBtn.Text == "连接")/*第一次连接*/
                {
                    try
                    {
                        client.Connect();
                        isConnect = true;
                    }
                    catch (Exception c)
                    {
                        MessageBox.Show(c.ToString() + "不符合IP格式");
                        receiveTb.AppendText(Line++ + "  未连接上了服务器:" + ip + "\n");
                    }
                }
                else if (connectBtn.Text == "重连")/*重新进行连接*/
                {
                    try
                    {
                        client.Close();
                        client.Connect();
                        isConnect = true;
                        receiveTb.AppendText(Line++ + " 成功与服务器重连" + ip + "\n");
                    }
                    catch (Exception c)
                    {
                        MessageBox.Show(c.ToString() + "不符合IP格式");
                        isConnect = false;
                    }
                }
            }
        }
Exemplo n.º 8
0
 public void Close()
 {
     try
     {
         if (tcpClient.State == Loxi.Core.Tcp.Mod.TcpConnectionStatus.Connecting)
         {
             return;
         }
         tcpClient?.Shutdown();
         tcpClient?.Close();
         if (tcpClient.State == Loxi.Core.Tcp.Mod.TcpConnectionStatus.Closed)
         {
             Start();
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 9
0
        /// <summary>退出当前加入的会议</summary>
        public void DisConnect()
        {
            if (client == null)
            {
                return;
            }
            try
            {
                Console.WriteLine("-> client.disconnect ->");
                client.Close();
                client.Dispose();
            }
            finally
            {
                client = null;

                Console.WriteLine("{0} -> client.server.disconnect = AudioIsRunning"
                                  , DateTime.Now.ToString("hh:mm:ss"));
                Audio.Instance.Stop();
                Console.WriteLine("{0} -> client.server.disconnect = VideoIsRunning"
                                  , DateTime.Now.ToString("hh:mm:ss"));
                Video.Instance.Stop();
            }
        }
Exemplo n.º 10
0
 private void btnDisconnect_Click(object sender, EventArgs e)
 {
     client.Close();
 }