Пример #1
0
 public static Host NewEchoing(EndPoint ep, Func<System.Net.IPEndPoint, bool> validateClientEndPointStrategy = null)
 {
     Host host = new Host(ep, LogicOfTo<string, string>.New((x) => { return x; }), validateClientEndPointStrategy);
     return host;
 }
Пример #2
0
        //#region Validation
        //public override bool Validate()
        //{
        //    bool returnValue = false;
        //    Func<string, object, string> oldStrategy = this.ServerStrategy;
        //    Func<string, object, string> echoStrategy = (req, state) =>
        //    {
        //        return req;
        //    };
        //    SimpleTCPClient client = null;
        //    //AutoResetEvent mre = new AutoResetEvent(false);
        //    //Exception trappedEx = null;

        //    try
        //    {
        //        lock (this._stateLock)
        //        {
        //            //swap out the old strategy with the echo strategy
        //            this.ServerStrategy = echoStrategy;

        //            //recycle
        //            this.Recycle();

        //            //grab a client and attempt to send a message 
        //            string data = string.Format("Validate for {0}", this.GetType().Name);

        //            client = new SimpleTCPClient(this.Address, this.Port);

        //            //sync first
        //            string resp = client.Send(data);

        //            if (resp != data) { throw new Exception("Sync echo failed"); }

        //            data = data + "1";
        //            resp = client.Send(data);

        //            if (resp != data) { throw new Exception("Sync echo failed"); }

        //            ////async
        //            //client.SendAsync(data, (socketState) =>
        //            //{
        //            //    if (socketState.ReceiveData.ToString() != data)
        //            //    {
        //            //        returnValue = false;
        //            //        trappedEx = new Exception("Async echo failed");
        //            //    }
        //            //    mre.Set();
        //            //});

        //            //mre.WaitOne();

        //            //if (trappedEx != null)
        //            //{
        //            //    throw trappedEx;
        //            //}

        //            //test the throttle
        //        }
        //        returnValue = true;
        //    }
        //    catch
        //    {
        //        returnValue = false;
        //    }
        //    finally
        //    {
        //        //swap back the old strategy
        //        this.ServerStrategy = oldStrategy;

        //        if (client != null)
        //        {
        //            client.Dispose();
        //        }

        //        //if (mre != null)
        //        //{
        //        //    mre.Dispose();
        //        //}
        //    }
        //    return returnValue;
        //}
        //#endregion

        #region Static Methods
        public static Host New(EndPoint ep, LogicOfTo<string, string> logic = null, Func<System.Net.IPEndPoint, bool> validateClientEndPointStrategy = null)
        {
            Host host = new Host(ep, logic, validateClientEndPointStrategy);
            return host;
        }