示例#1
0
        public override void SendMessages(int messageCount, TransmissionType transmissionType)
        {
            var flags = ENetBenchmark.GetPacketFlags(transmissionType);

            // Don't do this in a real-world application, ENet is not thread safe
            // send should only be called in the thread that also calls host.Service
            for (int i = 0; i < messageCount; i++)
            {
                Send(Message, 0, peer, flags);
            }
        }
        private void Broadcast(byte[] data, byte channelId, TransmissionType transmissionType)
        {
            Packet packet = default(Packet);
            var    flags  = ENetBenchmark.GetPacketFlags(transmissionType);

            packet.Create(data, data.Length, flags);
            host.Broadcast(channelId, ref packet);
            var messagesSent = host.PeersCount;

            Interlocked.Add(ref benchmarkStatistics.MessagesServerSent, messagesSent);
        }
        public EchoServer(Configuration config, BenchmarkStatistics benchmarkStatistics) : base(config)
        {
            this.config = config;
            this.benchmarkStatistics = benchmarkStatistics;
            timeout     = Utilities.CalculateTimeout(this.config.ServerTickRate);
            packetFlags = ENetBenchmark.GetPacketFlags(config.Transmission);

            host    = new Host();
            address = new Address();

            address.Port = (ushort)config.Port;
            address.SetHost(config.Address);
            serverThread          = new Thread(ListenLoop);
            serverThread.Name     = "Enet Server";
            serverThread.Priority = ThreadPriority.AboveNormal;
        }
示例#4
0
        public EchoClient(int id, Configuration config, BenchmarkStatistics benchmarkStatistics) : base(config)
        {
            this.id     = id;
            this.config = config;
            this.benchmarkStatistics = benchmarkStatistics;
            timeout     = Utilities.CalculateTimeout(this.config.ClientTickRate);
            packetFlags = ENetBenchmark.GetPacketFlags(config.Transmission);

            host    = new Host();
            address = new Address();
            address.SetHost(config.Address);
            address.Port = (ushort)config.Port;
            isDisposed   = false;

            listenThread              = new Thread(ListenLoop);
            listenThread.Name         = $"ENet Client {id}";
            listenThread.IsBackground = true;
        }