Exemple #1
0
 /// <summary>Delays the sending and receiving of incomingMessages by 'injectedDelay' milliseconds.
 /// </summary>
 /// <param name="bs">The binary connexion to use to send and receive on.</param>
 /// <param name="injectedDelay">delay time to inject</param>
 public DelayedBinaryChannel(IBinaryChannel bs, TimeSpan injectedDelay)
 {
     sendQueue = new SortedDictionary<long, byte[]>();
     dequeueQueue = new SortedDictionary<long, byte[]>();
     this.bs = bs;
     bs.MessagesReceived += BinaryNewMessageEvent;
     Messages = new List<byte[]>();
     timer = new HPTimer();
     InjectedDelay = injectedDelay;
 }
Exemple #2
0
        public virtual void Start()
        {
            running = true;
            client.Start();
            objectChannel = client.OpenObjectChannel(host, port,
                0, ChannelDeliveryRequirements.MostStrict);
            objectChannel.MessagesReceived += client_ReceivedObjectMessage;
            stringChannel = client.OpenStringChannel(host, port,
                1, ChannelDeliveryRequirements.MostStrict);
            stringChannel.MessagesReceived += client_ReceivedStringMessage;
            binaryChannel = client.OpenBinaryChannel(host, port,
                2, ChannelDeliveryRequirements.MostStrict);
            binaryChannel.MessagesReceived += client_ReceivedBinaryMessage;

            client.StartSeparateListeningThread();
            for (int i = 0; i < numberSenders; i++)
            {
                Thread t = new Thread(client_StartThread);
                t.IsBackground = true;
                t.Name = "Client thread #" + i;
                t.Start(i);
                threads.Add(t);
            }
        }
Exemple #3
0
        void BinaryNewMessageEvent(IBinaryChannel channel)
        {
            timer.Update();
            long currentTime = timer.ElapsedInMilliseconds;

            lock (dequeueQueue)
            {
                if (bs.Messages.Count > 0)
                {
                    byte[] b;
                    while ((b = bs.DequeueMessage(0)) != null)
                    {
                        while (dequeueQueue.ContainsKey(currentTime))
                            currentTime += 1;
                        dequeueQueue.Add(currentTime, b);
                    }
                }
            }
        }
Exemple #4
0
        private void client_ReceivedBinaryMessage(IBinaryChannel channel)
        {
            byte[] message;
            while ((message = channel.DequeueMessage(0)) != null)
            {
                if (!ByteUtils.Compare(message, StandardObjects.ByteMessage))
                {
                    Console.WriteLine("Invalid byte message: {0}",
                        ByteUtils.DumpBytes(message));
                    errorOccurred = true;
                }

                if (random.Next(0, 100) < 10)
                {
                    binaryChannel.Send(message);
                }
            }
        }