/// <summary> /// 连接服务器 /// </summary> /// <param name="hostname"></param> /// <param name="port"></param> /// <param name="strcode"></param> /// <param name="m_closecallack"></param> /// <returns></returns> public bool Connect(string hostname, int port, string strcode, AsyncCloseCallback m_closecallack, AxRDPCOMAPILib.AxRDPViewer viewer, AxMSTSCLib.AxMsRdpClient7NotSafeForScripting viewer2) { if (m_tcpclient != null) { m_tcpclient.Close(); m_tcpclient = null; } this.m_closecallack = m_closecallack; m_tcpclient = new TcpClient(); m_tcpclient.ReceiveTimeout = 10000; m_tcpclient.SendTimeout = 10000; try { m_tcpclient.Connect(hostname, port); if (!RdConnect(strcode)) { Logger.Trace("OnClose"); OnClose(null); return(false); } m_qos.SetQOS(256 * 1024, 128 * 1024); m_viewer = viewer; m_viewer2 = viewer2; if (!OpenRDPView()) { Logger.Trace("OnClose"); OnClose(null); return(false); } return(true); } catch (Exception e) { Logger.Trace(e); m_tcpclient = null; } return(false); }
/// <summary> /// 关闭事件 /// </summary> /// <param name="ar"></param> private void OnClose(IAsyncResult ar) { try { if (m_rdpviewtype == 1) { if (m_viewer2 != null) { m_viewer2.Disconnect(); m_viewer2 = null; } } else { if (m_viewer != null) { m_viewer.Disconnect(); m_viewer = null; } } } catch (Exception e) { } try { if (m_tcpclient != null) { TcpClient tcpclient = m_tcpclient; m_tcpclient = null; tcpclient.Close(); } }catch (Exception e) { } try { if (m_rdpclient != null) { TcpClient rdpclient = m_rdpclient; m_rdpclient = null; rdpclient.Close(); } } catch (Exception e) { } try { if (m_RdpListener != null) { TcpListener RdpListener = m_RdpListener; m_RdpListener = null; RdpListener.Stop(); } } catch (Exception e) { } if (m_closecallack != null) { AsyncCloseCallback closecallack = m_closecallack; m_closecallack = null; closecallack(); } }