/// <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="hostname"></param> /// <param name="port"></param> /// <param name="m_closecallack"></param> /// <returns></returns> public bool Connect(string hostname, int port, AsyncCloseCallback m_closecallack, string pwdcode) { if (m_rdpport == 0) { return(false); } 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 (!Handshake(pwdcode)) { OnClose(null); return(false); } m_pwdcode = pwdcode; m_start = 0; if (m_tcprdp != null) { try { m_tcprdp.Close(); } catch { } m_tcprdp = null; } m_qos.SetQOS(128 * 1024, 256 * 1024); try { m_buffer = null; m_buffer = new byte[RECV_BUFF_SIZE]; m_tcpclient.GetStream().BeginRead(m_buffer, 0, m_buffer.Length, OnRecvData, this); } catch (Exception e) { Logger.Trace(e); } return(true); } catch (Exception e) { Logger.Trace(e); m_tcpclient = null; } return(false); }