コード例 #1
0
    public void Execute()
    {
        string receivedData;
        //var timeout = new TimeSpan(60000);
        var timeout = new TimeSpan(600000); //>> DEBUG - longer timeout

        Responder.Bind("tcp://" + Address + ":" + Port);
        while (true) //>> while not terminated...
        {
            if (Responder.TryReceiveFrameString(timeout, Encoding.Unicode, out receivedData))
            {
                IOBuffer = receivedData;
                log.Info(receivedData);
                if (IOBuffer != "")
                {
                    lock (owner)
                    {
                        owner.ProcessData();
                        Responder.SendFrame(System.Text.Encoding.Unicode.GetBytes(IOBuffer), false);
                    }
                }
            }
        }

        //Responder.unbind("tcp://" + Address + ":" + Port);
    }
コード例 #2
0
        public void One_Responder_1_Requester()
        {
            var echoWorker    = new ResponderWorker();
            var workerFactory = new ResponderWorkerFactory(request => echoWorker);

            using (var responder = new Responder(workerFactory))
                using (var requester = new Requester())
                {
                    var endpoint = GetEndpoint();
                    responder.Bind(endpoint);
                    requester.Connect(endpoint);

                    Thread.Sleep(100);

                    var sw          = Stopwatch.StartNew();
                    var messageSent = new TestMessage();
                    for (var i = 0; i < NumberOfRequests; i++)
                    {
                        requester.Request(messageSent);
                    }
                    sw.Stop();

                    Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds);
                }
        }
コード例 #3
0
        private void One_Responder_N_Requesters(int n)
        {
            var echoWorker    = new ResponderWorker();
            var workerFactory = new ResponderWorkerFactory(request => echoWorker);

            using (var responder = new Responder(workerFactory))
            {
                var endpoint = GetEndpoint();
                responder.Bind(endpoint);

                var requesters = Enumerable.Range(0, n).Select(x => new Requester()).ToList();
                foreach (var requester in requesters)
                {
                    requester.Connect(endpoint);
                }

                Thread.Sleep(100);

                var threadsStartedSignal = new CounterSignal(n, 0);
                var startSignal          = new ManualResetEventSlim();
                var tasks = new List <Task>();
                foreach (var requester in requesters)
                {
                    var req  = requester;
                    var task = Task.Factory.StartNew(() =>
                    {
                        threadsStartedSignal.Increment();
                        startSignal.Wait();

                        var message = new TestMessage();
                        for (var i = 0; i < NumberOfRequests / n; i++)
                        {
                            req.Request(message);
                        }
                    }, TaskCreationOptions.LongRunning);
                    tasks.Add(task);
                }
                Assert.IsTrue(threadsStartedSignal.Wait(TimeSpan.FromSeconds(1)));

                var sw = Stopwatch.StartNew();
                startSignal.Set();
                Assert.IsTrue(Task.WhenAll(tasks).Wait(TimeSpan.FromMinutes(1)));
                sw.Stop();

                foreach (var requester in requesters)
                {
                    requester.Disconnect();
                }

                Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds);
            }
        }
コード例 #4
0
        public void One_Responder_1_Requester()
        {
            var echoWorker = new ResponderWorker();
            var workerFactory = new ResponderWorkerFactory(request => echoWorker);
            using (var responder = new Responder(workerFactory))
            using (var requester = new Requester())
            {
                var endpoint = GetEndpoint();
                responder.Bind(endpoint);
                requester.Connect(endpoint);

                Thread.Sleep(100);

                var sw = Stopwatch.StartNew();
                var messageSent = new TestMessage();
                for (var i = 0; i < NumberOfRequests; i++)
                {
                    requester.Request(messageSent);
                }
                sw.Stop();

                Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds);
            }
        }
コード例 #5
0
        private void One_Responder_N_Requesters(int n)
        {
            var echoWorker = new ResponderWorker();
            var workerFactory = new ResponderWorkerFactory(request => echoWorker);
            using (var responder = new Responder(workerFactory))
            {
                var endpoint = GetEndpoint();
                responder.Bind(endpoint);

                var requesters = Enumerable.Range(0, n).Select(x => new Requester()).ToList();
                foreach (var requester in requesters)
                {
                    requester.Connect(endpoint);
                }

                Thread.Sleep(100);

                var threadsStartedSignal = new CounterSignal(n, 0);
                var startSignal = new ManualResetEventSlim();
                var tasks = new List<Task>();
                foreach (var requester in requesters)
                {
                    var req = requester;
                    var task = Task.Factory.StartNew(() =>
                    {
                        threadsStartedSignal.Increment();
                        startSignal.Wait();

                        var message = new TestMessage();
                        for (var i = 0; i < NumberOfRequests / n; i++)
                        {
                            req.Request(message);
                        }
                    }, TaskCreationOptions.LongRunning);
                    tasks.Add(task);
                }
                Assert.IsTrue(threadsStartedSignal.Wait(TimeSpan.FromSeconds(1)));

                var sw = Stopwatch.StartNew();
                startSignal.Set();
                Assert.IsTrue(Task.WhenAll(tasks).Wait(TimeSpan.FromMinutes(1)));
                sw.Stop();

                foreach (var requester in requesters)
                {
                    requester.Disconnect();
                }

                Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds);
            }
        }