예제 #1
0
        public bool Start(string Ip, int Port)
        {
            try
            {
                if (Channel != null)
                {
                    return(false);
                }

                LocalIp   = Ip;
                LocalPort = Port;

                Log.Debug("RpcServer", "Start on : " + Ip + ":" + Port);

                Channel = new TcpServerChannel("Server" + Port, Port);
                ChannelServices.RegisterChannel(Channel, false);
                RegisteredTypes = RpcObject.RegisterHandlers(true, AllowedID);

                ServerMgr.Server = this;
                Mgr = GetLocalObject <ServerMgr>();
                Mgr.StartingPort = StartingPort;

                Log.Success("RpcServer", "Listening on : " + Ip + ":" + Port);
            }
            catch (Exception e)
            {
                Log.Error("RpcServer", e.Message);
                Log.Notice("RpcServer", "Can not start RPC : " + Ip + ":" + Port);

                return(false);
            }

            return(true);
        }
예제 #2
0
        public bool Connect(string Ip, int Port)
        {
            Log.Debug("RpcClient", "Connect : " + Ip + ":" + Port);

            RpcServerIp   = Ip;
            RpcServerPort = Port;
            Connecting    = true;

            try
            {
                if (Channel != null)
                {
                    return(false);
                }

                Log.Debug("RpcClient", "Connecting to : " + Ip);

                if (!Pinger.IsAlive)
                {
                    Pinger.Start();
                }

                Channel = new TcpClientChannel(ServerName, null);
                ChannelServices.RegisterChannel(Channel, false);

                Mgr  = Activator.GetObject(typeof(ServerMgr), "tcp://" + Ip + ":" + Port + "/" + typeof(ServerMgr).Name) as ServerMgr;
                Info = Mgr.Connect(ServerName, ServerIp);

                if (Info == null)
                {
                    return(false);
                }

                Log.Debug("RpcClient", "Listening on : " + ServerIp + ":" + Info.Port);

                ServerChannel = new TcpServerChannel("Server" + Info.RpcID, Info.Port);
                ChannelServices.RegisterChannel(ServerChannel, false);

                RegisteredTypes = RpcObject.RegisterHandlers(false, AllowedID);
                foreach (Type t in RegisteredTypes[1])
                {
                    RpcServer.GetObject(t, Info.Ip, Info.Port).MyInfo = Info;
                }

                Mgr.Connected(Info.RpcID);

                Log.Success("RpcClient", "Connected to : " + ServerIp + ":" + RpcServerPort + ", Listen on : " + Info.Ip + ":" + Info.Port);

                foreach (Type t in RegisteredTypes[1])
                {
                    RpcServer.GetObject(t, Info.Ip, Info.Port).OnServerConnected();
                }

                Connecting = false;
            }
            catch (Exception e)
            {
                Log.Error("RpcClient", e.ToString());
                Log.Notice("RpcClient", "Can not start RPC : " + Ip + ":" + Port);

                Connecting = false;
                Mgr        = null;
                Info       = null;

                return(false);
            }

            return(true);
        }