Esempio n. 1
0
        public static FFAcceptor Listen(string host, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
        {
            string[] strList = host.Split(":");
            if (strList.Length != 3)
            {
                return(null);
            }
            string ip = strList[1];

            string[] ipList = ip.Split("//");
            if (ipList.Length == 2)
            {
                ip = ipList[1];
            }
            else
            {
                ip = ipList[0];
            }

            int        port       = int.Parse(strList[2]);
            SocketCtrl ctrl       = new SocketCtrl(funcMsg, funcBroken);
            FFAcceptor ffacceptor = new FFAcceptor(ctrl);

            if (ffacceptor.Listen(ip, port))
            {
                return(ffacceptor);
            }
            return(null);
        }
Esempio n. 2
0
        public bool Init(string strBrokerHost, string strGateListenIpPort, int nGateIndex = 0)
        {
            m_nGateIndex  = nGateIndex;
            m_strGateName = string.Format("gate#{0}", m_nGateIndex);
            m_ffrpc       = new FFRpc(m_strGateName);
            if (m_ffrpc.Open(strBrokerHost) == false)
            {
                FFLog.Error("gate ffrpc open failed!");
                return(false);
            }

            m_ffrpc.Reg <GateChangeLogicNodeReq, EmptyMsgRet>(this.ChangeSessionLogic);
            m_ffrpc.Reg <GateCloseSessionReq, EmptyMsgRet>(this.CloseSession);
            m_ffrpc.Reg <GateRouteMsgToSessionReq, EmptyMsgRet>(this.RouteMsgToSession);
            m_ffrpc.Reg <GateBroadcastMsgToSessionReq, EmptyMsgRet>(this.BroadcastMsgToSession);

            m_acceptor = FFNet.Listen(strGateListenIpPort, new SocketMsgHandler(HandleMsg), new SocketBrokenHandler(HandleBroken));
            if (m_acceptor != null)
            {
                FFLog.Trace(string.Format("FFGate open....{0} ok", strGateListenIpPort));
            }
            else
            {
                FFLog.Error(string.Format("FFGate open....{0} failed", strGateListenIpPort));
            }
            return(true);
        }
Esempio n. 3
0
 public FFGate(string strName = "gate#0")
 {
     m_nIDGenerator = 0;
     m_nGateIndex   = 0;
     m_strGateName  = strName;
     m_ffrpc        = null;
     m_dictClients  = new Dictionary <Int64, ClientInfo>();
     m_msgEmpty     = new EmptyMsgRet();
     m_acceptor     = null;
 }
Esempio n. 4
0
        public static FFAcceptor listen(string ip, int port, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
        {
            SocketCtrl ctrl       = new SocketCtrl(funcMsg, funcBroken);
            FFAcceptor ffacceptor = new FFAcceptor(new SocketRecvHandler(ctrl.handleRecv), new SocketBrokenHandler(ctrl.handleBroken));

            if (ffacceptor.listen(ip, port))
            {
                return(ffacceptor);
            }
            return(null);
        }
Esempio n. 5
0
        public bool Open(string strBrokerCfg)
        {
            if (strBrokerCfg.Length > 0)
            {
                m_strListenHost = strBrokerCfg;
            }

            m_acceptor = FFNet.Listen(m_strListenHost, new SocketMsgHandler(HandleMsg), new SocketBrokenHandler(HandleBroken));
            if (m_acceptor != null)
            {
                FFLog.Trace(string.Format("FFBroker open....{0} ok", m_strListenHost));
            }
            else
            {
                FFLog.Trace(string.Format("FFBroker open....{0} failed", m_strListenHost));
            }
            return(true);
        }