Esempio n. 1
0
        public static void Main(string[] args)
        {
            string   host     = "tcp://127.0.0.1:43210";
            FFBroker ffbroker = new FFBroker();

            ffbroker.Open(host);

            string strServiceName = "worker#0";
            FFRpc  ffrpc          = new FFRpc(strServiceName);

            if (ffrpc.Open(host) == false)
            {
                FFLog.Trace("ffrpc open failed!");
            }
            ffrpc.Reg((SessionEnterWorkerReq req) =>
            {
                FFLog.Trace(string.Format("ffrpc SessionEnterWorkerReq £¡£¡£¡FromGate={0}", req.From_gate));
                return(req);
            });
            Console.ReadKey();
            ffrpc.GetTaskQueue().Post(() =>
            {
                SessionEnterWorkerReq reqMsg = new SessionEnterWorkerReq()
                {
                    From_gate = "gate#0"
                };
                WorkerCallMsgReq reqWorkerCall = new WorkerCallMsgReq();
                //ffrpc.Call(strServiceName, reqMsg);
                reqMsg.From_gate = "gate#1";
                ffrpc.Call(strServiceName, reqWorkerCall, (SessionEnterWorkerReq retMsg) =>
                {
                    FFLog.Trace(string.Format("ffrpc SessionEnterWorkerReq return£¡£¡£¡FromGate={0}", retMsg.From_gate));
                });
            });

            //FFNet.Timerout(1000, Theout);
            //FFNet.Timerout(2000, Theout);
            FFNet.Timerout(100000, () =>
            {
                FFLog.Debug("AAAAAAAAAAAAAAA1");
                ffrpc.Close();
            });
            FFLog.Trace(string.Format("main! {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));

            AppDomain.CurrentDomain.ProcessExit += (sender, arg) =>
            {
                FFLog.Trace("exist!!");
            };
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => {
                e.Cancel = true;
                FFLog.Trace("exist3!!");

                FFNet.Cleanup();
                FFLog.Cleanup();
            };
            Console.ReadKey();
            FFLog.Trace("exist!!");
            FFNet.Cleanup();
            FFLog.Cleanup();
        }
Esempio n. 2
0
        public EmptyMsgRet OnSessionEnterWorkerReq(SessionEnterWorkerReq reqMsg)
        {
            Int64 nBeginUs   = DateTime.Now.Ticks / 10;
            Int64 nSessionID = reqMsg.SessionId;

            FFLog.Trace(string.Format("worker OnSessionEnterWorkerReq session={0}", nSessionID));

            this.funcSessionOnEnterWorker?.Invoke(nSessionID, reqMsg.FromWorker, reqMsg.ExtraData);
            PerfMonitor.Instance().AddPerf("OnEnterWorker", DateTime.Now.Ticks / 10 - nBeginUs);
            return(RPC_NONE);
        }
Esempio n. 3
0
        //!切换worker
        public EmptyMsgRet ChangeSessionLogic(GateChangeLogicNodeReq reqMsg)
        {
            if (m_dictClients.ContainsKey(reqMsg.Session_id) == false)
            {
                return(m_msgEmpty);
            }
            ClientInfo            cinfo    = m_dictClients[reqMsg.Session_id];
            SessionEnterWorkerReq msgEnter = new SessionEnterWorkerReq()
            {
            };

            msgEnter.From_worker = cinfo.strAllocWorker;
            cinfo.strAllocWorker = reqMsg.Alloc_worker;

            msgEnter.Session_id = reqMsg.Session_id;
            msgEnter.From_gate  = m_strGateName;
            msgEnter.Session_ip = cinfo.sockObj.GetIP();

            msgEnter.To_worker  = reqMsg.Alloc_worker;
            msgEnter.Extra_data = reqMsg.Extra_data;
            m_ffrpc.Call(reqMsg.Alloc_worker, msgEnter);
            return(m_msgEmpty);
        }
Esempio n. 4
0
        //!切换worker
        public EmptyMsgRet ChangeSessionLogic(GateChangeLogicNodeReq reqMsg)
        {
            FFLog.Trace(string.Format("FFGate ChangeSessionLogic....sessionid={0}", reqMsg.SessionId));
            if (m_dictClients.ContainsKey(reqMsg.SessionId) == false)
            {
                return(m_msgEmpty);
            }
            ClientInfo            cinfo    = m_dictClients[reqMsg.SessionId];
            SessionEnterWorkerReq msgEnter = new SessionEnterWorkerReq()
            {
            };

            msgEnter.FromWorker  = cinfo.strAllocWorker;
            cinfo.strAllocWorker = reqMsg.AllocWorker;

            msgEnter.SessionId = reqMsg.SessionId;
            msgEnter.FromGate  = m_strGateName;
            msgEnter.SessionIp = cinfo.sockObj.GetIP();

            msgEnter.ToWorker  = reqMsg.AllocWorker;
            msgEnter.ExtraData = reqMsg.ExtraData;
            m_ffrpc.Call(reqMsg.AllocWorker, msgEnter);
            return(m_msgEmpty);
        }