예제 #1
0
        private new static readonly Logger Logger = LogManager.CreateLogger(); // hide the Server.Logger so that tiny-logger can show the actual server as log source.

        public MooNetServer()
        {
            this.OnConnect    += MooNetServer_OnConnect;
            this.OnDisconnect += MooNetServer_OnDisconnect;
            this.DataReceived += (sender, e) => MooNetRouter.Route(e);
            this.DataSent     += (sender, e) => { };
        }
예제 #2
0
        /// <summary>
        /// Makes an RPC over remote client.
        /// </summary>
        /// <param name="method">The method to call.</param>
        /// <param name="controller">The rpc controller.</param>
        /// <param name="request">The request message.</param>
        /// <param name="responsePrototype">The response message.</param>
        /// <param name="done">Action to run when client responds RPC.</param>
        public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action <IMessage> done)
        {
            var serviceName = method.Service.FullName;
            var serviceHash = StringHashHelper.HashIdentity(serviceName);

            if (!this.Services.ContainsKey(serviceHash))
            {
                Logger.Error("Not bound to client service {0} [0x{1}] yet.", serviceName, serviceHash.ToString("X8"));
                return;
            }

            var serviceId = this.Services[serviceHash];
            var token     = this._tokenCounter++;

            RPCCallbacks.Add(token, new RPCCallback(done, responsePrototype.WeakToBuilder()));

            var packet = new PacketOut((byte)serviceId, MooNetRouter.GetMethodId(method), (uint)token, this._listenerId, request);

            this.Connection.Send(packet);
        }