Example #1
0
        public void Stop()
        {
            client.Send(QcNet.QcCmd.MakeCmd(QcNet.QcProtocol.QcCommand.QcLoginOut, User.Name));
            client.Close();

            //循环遍历发送登出消息
        }
Example #2
0
        LicenseRetCode PostLicenseMessage(string type, string arg)
        {
            int            count  = 3;
            QcMsgClient    client = new QcMsgClient(null, null);
            AutoResetEvent are    = new AutoResetEvent(false);
            QcCmd          retcmd = null;
            string         cmd    = QcCmd.MakeCmd(QcProtocol.QcCommand.QcCheckLicense, type, arg);

            try
            {
                //client =;
                client.ConnectedServer += (o, e) =>
                {
                    client.Send(cmd);
                };
                client.ReceiveCmd += (o, e) =>
                {
                    retcmd = e.Cmd;
                    are.Set();
                    //接收消息
                };
CONTINUE:
                client.Connect(QcMessagner.IP, QcMessagner.Port);
                if (are.WaitOne(5000))//3秒钟超时连接
                {
                    LicenseRetCode ret = LicenseRetCode.授权未知错误01;
                    //if (retcmd == null)
                    //{
                    //    Thread.Sleep(500);//有可能消息接收 事件还没有给retcmd赋值,因此延迟500毫秒
                    //}
                    if (retcmd != null)
                    {
                        string t_Test = retcmd.tokens(1);
                        ret = (LicenseRetCode)Enum.Parse(typeof(LicenseRetCode), t_Test);
                    }
                    return(ret);
                }
                else
                {
                    if (count > 0)
                    {
                        count--;
                        goto CONTINUE;
                    }
                    else
                    {
                        return(LicenseRetCode.授权服务器连接超时);
                    }
                }
            }
            catch (Exception e)
            {
                QcLog.LogString(e.Message + e.StackTrace);
                //System.Windows.Forms.MessageBox.Show(e.Message + e.StackTrace);
                return(LicenseRetCode.授权未知错误);
            }
            finally
            {
                //这里该怎样断开服务器上的连接呢?
                if (client != null)
                {
                    client.Close();
                }
                are.Set();
            }
        }