Ejemplo n.º 1
0
        internal virtual PendingCall Call(string serviceName, string methodName, RpcMessage.Parameter[] parameters,
                                          AsyncCallback callback, object state)
        {
            var message = new RpcMessage
            {
                CallMessage = new RpcMessage.Call
                {
                    Service = serviceName, Method = methodName, ExpectsResult = true
                }
            };

            if (parameters != null)
            {
                foreach (var param in parameters)
                {
                    message.CallMessage.Parameters.Add(param);
                }
            }

            PendingCall pendingCall;

            lock (mPendingCalls)
            {
                int id = GetFreeId();
                message.Id  = id;
                pendingCall = new PendingCall(id, serviceName, methodName, callback, state);
                mPendingCalls.Add(id, pendingCall);
            }

            //channel send is thread-safe already
            mController.Send(message);

            return(pendingCall);
        }
Ejemplo n.º 2
0
        public RpcClient(RpcController controller, int pingPeriod = Timeout.Infinite)
        {
            mController       = controller;
            controller.Client = this;

            ResponseTimeout = TimeSpan.MaxValue;
            mPing           = new PeriodicTask(pingPeriod)
            {
                OnPeriod = () =>
                {
                    if (mController.Channel == null)
                    {
                        return;
                    }

                    if (!mController.Channel.IsReady)
                    {
                        //Console.WriteLine("!isReady");
                        return;
                    }

                    mController.Send(new RpcMessage {
                        CallMessage = new RpcMessage.Call {
                            Service = ""
                        }
                    });
                    //Console.WriteLine("{2}: read: {0}, write: {1}", mController.Channel.TotalBytesRead, mController.Channel.TotalBytesWritten, DateTime.Now.ToString("mm:ss.hhh"));
                }
            };

            mPing.Start();
        }