Esempio n. 1
0
        public bool ConnectToBroker()
        {
            m_socketBroker = FFNet.Connect(m_strBrokerHost, new SocketMsgHandler(HandleMsg), new SocketBrokenHandler(HandleBroken));
            if (null == m_socketBroker)
            {
                return(false);
            }
            RegisterToBrokerReq reqMsg = new RegisterToBrokerReq {
                Node_type = 2, Service_name = m_strServiceName
            };

            FFNet.SendMsg(m_socketBroker, (UInt16)FFRPC_CMD.REGISTER_TO_BROKER_REQ, reqMsg);
            return(true);
        }
Esempio n. 2
0
        public void HandleMsg(IFFSocket ffsocket, UInt16 cmd, byte[] strMsg)
        {
            //FFLog.Trace(string.Format("FFBroker handleMsg....{0}, {1} [{2}]", cmd, strMsg.Length, System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));
            try
            {
                switch ((FFRPC_CMD)cmd)
                {
                case FFRPC_CMD.REGISTER_TO_BROKER_REQ:
                {
                    RegisterToBrokerReq reqMsg = new RegisterToBrokerReq();
                    FFNet.DecodeMsg(reqMsg, strMsg);
                    FFLog.Trace(string.Format("FFBroker handleMsg.REGISTER_TO_BROKER_REQ....{0}, {1}", reqMsg.Node_type, reqMsg.Service_name));
                    if (FFRPC_NODE_TYPE.RPC_NODE == (FFRPC_NODE_TYPE)reqMsg.Node_type)
                    {
                        if (m_brokerData.Service2node_id.ContainsKey(reqMsg.Service_name))
                        {
                            FFLog.Error(string.Format("FFBroker handleMsg servicename exist....{0}, {1}", reqMsg.Node_type, reqMsg.Service_name));
                            ffsocket.Close();
                            return;
                        }
                        Int64 nNodeID = allocNodeId();
                        m_dictSockets[nNodeID] = ffsocket;
                        m_brokerData.Service2node_id[reqMsg.Service_name] = nNodeID;
                        m_brokerData.Node_id = nNodeID;
                        SyncNodeInfo(m_brokerData, ffsocket);        //!广播给所有的子节点
                    }
                } break;

                case FFRPC_CMD.BROKER_ROUTE_MSG:
                {
                    BrokerRouteMsgReq reqMsg = new BrokerRouteMsgReq();
                    FFNet.DecodeMsg(reqMsg, strMsg);
                    FFLog.Trace(string.Format("FFBroker.BROKER_ROUTE_MSG service={0},func={1} Callback={2}",
                                              reqMsg.Dest_service_name, reqMsg.Dest_msg_name, reqMsg.Callback_id));
                    if (!m_dictSockets.ContainsKey(reqMsg.Dest_node_id))
                    {
                        return;
                    }
                    IFFSocket destSocket = m_dictSockets[reqMsg.Dest_node_id];
                    FFNet.SendMsg(destSocket, (UInt16)FFRPC_CMD.BROKER_TO_CLIENT_MSG, reqMsg);
                } break;

                default: break;
                }
            }
            catch (Exception ex)
            {
                FFLog.Error("FFBroker.Error:" + ex.Message);
            }
        }
Esempio n. 3
0
        public bool connectToBroker()
        {
            m_socketBroker = FFNet.connect(m_strBrokerIP, m_nBrokerPort, new SocketMsgHandler(handleMsg), new SocketBrokenHandler(handleBroken));
            if (null == m_socketBroker)
            {
                return(false);
            }
            RegisterToBrokerReq reqMsg = new RegisterToBrokerReq();

            reqMsg.Node_type    = 2;
            reqMsg.Service_name = m_strServiceName;

            FFNet.sendMsg(m_socketBroker, 2, reqMsg);
            return(true);
        }