コード例 #1
0
        public void AddResponse(APacket packet, bool immediate = true)
        {
            packet.Destination = this;
            PacketWriterWorker worker = PacketWriterWorker.Instance;

            if (immediate == true)
            {
                worker.Packets.Add(packet);
            }
            else
            {
                _packetQueue.Add(packet);
            }
        }
コード例 #2
0
        public PacketWriterWorker(System.Collections.Concurrent.BlockingCollection <APacket> packets, uint numberOfInstance)
        {
            Packets  = packets;
            Instance = this;
            MyMutex  = new Mutex();

            for (uint i = 0u; i < numberOfInstance; ++i)
            {
                Task.Factory.StartNew(() =>
                {
                    uint myId = i;

                    foreach (var packet in packets.GetConsumingEnumerable())
                    {
                        NetworkStream wrapper = new NetworkStream(packet.Destination.Socket);
                        lock (packet.Destination.Socket)
                        {
                            System.Diagnostics.Debug.WriteLine("SendingTo " + packet.Destination.Socket.RemoteEndPoint + " " + packet.Name);
                            packet.Write(wrapper, packet.Destination);
                        }
                    }
                }, TaskCreationOptions.LongRunning);
            }
        }