Exemplo n.º 1
0
        public int AppMain_start()
        {
            m_Protocol = new TcpClientAppProtocol(updTimer, true, DataArea, false);

            m_Comm            = new TCPClient(IpStr, port, CommConst.BUFFERSIZE, m_Protocol);
            m_Protocol.m_Comm = m_Comm;
            //开始尝试连接
            m_Protocol.ClearCache();
            int StartTick = HyTick.TickTimeGet();

            m_Comm.StartClient();
            while (!m_Comm.Connected)
            {
                //等待10秒是否连接成功
                if (HyTick.TickTimeIsArrived(StartTick, 10000))
                {
                    //MessageBox.Show("连接失败!");
                    return(-1);
                }
                Application.DoEvents();
            }
            m_Protocol.Main_Start();
            //MessageBox.Show("连接成功!");
            return(1);
        }
Exemplo n.º 2
0
        public int AppMain_stop()
        {
            try
            {
                if (m_Protocol == null || m_Comm == null)
                {
                    MessageBox.Show("当前未连接!");
                    return(-1);
                }
                m_Protocol.Main_Stop();
                m_Comm.StopClient();
                m_Protocol = null;
                m_Comm     = null;

                return(0);
            }
            catch
            {
                return(-2);
            }
        }