Пример #1
0
        public bool Connect()
        {
            if (IsConnected)
            {
                Disconnect();
            }
            m_client = new TcpClientHandler(m_ip, m_port);
            if (m_client.Connect())
            {
                m_client.Disconnected += m_client_Disconnected;
                m_client.ReceivedFull += m_client_ReceivedFull;
                return(true);
            }

            m_lastConnectionError = m_client.LastConnectError;
            m_client = null;
            return(false);
        }
Пример #2
0
		public bool Connect()
		{
			if (IsConnected)
			{
				Disconnect();
			}
			m_client = new TcpClientHandler(m_ip, m_port);
			if (m_client.Connect())
			{
				m_client.Disconnected += m_client_Disconnected;
				m_client.ReceivedFull += m_client_ReceivedFull;
				return true;
			}

			m_lastConnectionError = m_client.LastConnectError;
			m_client = null;
			return false;
		}
Пример #3
0
    public void threadFunc()
    {
        String msg;

        tcpClientHandler.Connect(HOST, PORT);
        msgWasInit = tcpClientHandler.Write("mark_target");
        while (msgWasInit)
        {
            try
            {
                msg = tcpClientHandler.Read();
            }
            catch (Exception e)
            {
                return;
            }
            if (msg != null)
            {
                Debug.Log(msg);
            }
        }
    }
Пример #4
0
        /// <summary>
        /// Connect to a server. If already connected to one, it will be disconnected to connect to the new one
        /// </summary>
        /// <returns>True if able to connect, or false if it didn't succeed</returns>
        public bool Connect()
        {
            if (m_ip == null)
            {
                throw new InvalidOperationException("Can not connect to a server if no Ip address is specified");
            }
            if (IsConnected)
            {
                Disconnect();
            }
            m_client = new TcpClientHandler(m_ip, m_port);
            if (m_client.Connect())
            {
                m_client.Disconnected += m_client_Disconnected;
                m_client.ReceivedFull += m_client_ReceivedFull;
                return(true);
            }

            m_lastConnectionError = m_client.LastConnectError;
            m_client = null;
            return(false);
        }
Пример #5
0
        /// <summary>
        /// 启动Client连接
        /// </summary>
        public void StartConnectServer()
        {

            IPEndPoint _remote=new IPEndPoint(IPAddress.Parse(strRemoteIP),nRemotePort);
            IPEndPoint _local=new IPEndPoint(IPAddress.Any,nLocalPort);
            NetTransCondiction ntc=new NetTransCondiction();
            ntc.IsPackHead =true;
            ntc.IsShakeHand =true;

            tch = new TcpClientHandler(_local,_remote,ntc);
            tch.Connected += new System.EventHandler<NetEventArgs>(tsh_Connected);
            tch.DisConnected += new System.EventHandler<NetEventArgs>(tsh_DisConnected);
            tch.RecvMessage += new System.EventHandler<NetEventArgs>(tsh_RecvMessage);
            tch.SendMessage += new System.EventHandler<NetEventArgs>(tsh_SendMessage);
            tch._isPermitReconnect = true;
            try
            {
                tch.Connect();
            }
            catch (Exception ex)
            {
                LOG.LogHelper.WriteLog("连接服务器异常", ex);
            }
        }