From a63e20eb350cab45cb70f28e8e6bf69291c40063 Mon Sep 17 00:00:00 2001 From: Johannes Deml Date: Mon, 3 Apr 2023 21:30:54 +0200 Subject: [PATCH] Add option to for native sockets commandline arguments --- NetworkBenchmarkDotNet/Configuration/Configuration.cs | 8 ++++++++ NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoClient.cs | 8 +++----- NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoServer.cs | 4 +--- NetworkBenchmarkDotNet/Utils/CommandLineUtilities.cs | 6 +++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/NetworkBenchmarkDotNet/Configuration/Configuration.cs b/NetworkBenchmarkDotNet/Configuration/Configuration.cs index e3750c1..abec7b5 100644 --- a/NetworkBenchmarkDotNet/Configuration/Configuration.cs +++ b/NetworkBenchmarkDotNet/Configuration/Configuration.cs @@ -99,6 +99,12 @@ public class Configuration /// public int ServerTickRate { get; set; } + /// + /// Special feature of LiteNetLib for using faster socket implementation + /// This is currently not supported for all platforms + /// + public bool UseNativeSockets { get; set; } + public byte[] Message { get; private set; } public void PrepareForNewBenchmark() @@ -210,6 +216,7 @@ public void AppendCommandlineInstruction(StringBuilder sb) sb.Append($" --message-payload {MessagePayload}"); sb.Append($" --client-tick-rate {ClientTickRate}"); sb.Append($" --server-tick-rate {ServerTickRate}"); + sb.Append($" --use-native-sockets {UseNativeSockets}"); } public static void ApplyPredefinedBenchmarkConfiguration(Configuration config) @@ -225,6 +232,7 @@ public static void ApplyPredefinedBenchmarkConfiguration(Configuration config) config.MessageByteSize = 32; config.ServerTickRate = 60; config.ClientTickRate = 60; + config.UseNativeSockets = true; } } } diff --git a/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoClient.cs b/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoClient.cs index 06a4d62..dcb5871 100644 --- a/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoClient.cs +++ b/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoClient.cs @@ -28,7 +28,6 @@ internal class EchoClient : AClient, IClient, INetEventListener private readonly BenchmarkStatistics benchmarkStatistics; private readonly NetManager netManager; - private readonly DeliveryMethod deliveryMethod; private NetPeer peer; public EchoClient(int id, Configuration config, BenchmarkStatistics benchmarkStatistics) : base(config) @@ -36,7 +35,6 @@ public EchoClient(int id, Configuration config, BenchmarkStatistics benchmarkSta this.id = id; this.config = config; this.benchmarkStatistics = benchmarkStatistics; - deliveryMethod = LiteNetLibBenchmark.GetDeliveryMethod(config.Transmission); netManager = new NetManager(this); if (!config.Address.Contains(':')) @@ -44,7 +42,7 @@ public EchoClient(int id, Configuration config, BenchmarkStatistics benchmarkSta netManager.IPv6Mode = IPv6Mode.Disabled; } - //netManager.UseNativeSockets = true; + netManager.UseNativeSockets = config.UseNativeSockets; netManager.UpdateTime = Utilities.CalculateTimeout(config.ClientTickRate); netManager.UnsyncedEvents = true; netManager.DisconnectTimeout = 10000; @@ -138,14 +136,14 @@ void INetEventListener.OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnec isConnected = false; } - void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, byte channelNumber, DeliveryMethod deliverymethod) + void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, byte channelNumber, DeliveryMethod deliveryMethod) { if (BenchmarkRunning) { Interlocked.Increment(ref benchmarkStatistics.MessagesClientReceived); if (!ManualMode) { - Send(Message, deliverymethod); + Send(Message, deliveryMethod); netManager.TriggerUpdate(); } } diff --git a/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoServer.cs b/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoServer.cs index f17b749..94c20d9 100644 --- a/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoServer.cs +++ b/NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoServer.cs @@ -23,17 +23,15 @@ internal class EchoServer : AServer, INetEventListener private readonly Configuration config; private readonly BenchmarkStatistics benchmarkStatistics; private readonly NetManager netManager; - private readonly DeliveryMethod deliveryMethod; public EchoServer(Configuration config, BenchmarkStatistics benchmarkStatistics) : base(config) { this.config = config; this.benchmarkStatistics = benchmarkStatistics; - deliveryMethod = LiteNetLibBenchmark.GetDeliveryMethod(config.Transmission); netManager = new NetManager(this); netManager.UpdateTime = Utilities.CalculateTimeout(config.ServerTickRate); - //netManager.UseNativeSockets = true; + netManager.UseNativeSockets = config.UseNativeSockets; if (!config.Address.Contains(':')) { netManager.IPv6Mode = IPv6Mode.Disabled; diff --git a/NetworkBenchmarkDotNet/Utils/CommandLineUtilities.cs b/NetworkBenchmarkDotNet/Utils/CommandLineUtilities.cs index 4ab9382..06cc9bb 100644 --- a/NetworkBenchmarkDotNet/Utils/CommandLineUtilities.cs +++ b/NetworkBenchmarkDotNet/Utils/CommandLineUtilities.cs @@ -77,7 +77,11 @@ public static RootCommand GenerateRootCommand() new Option( "--server-tick-rate", getDefaultValue: () => 60, - "Server ticks per second if supported") + "Server ticks per second if supported"), + new Option( + "--use-native-sockets", + getDefaultValue: () => true, + "Use native Sockets (LiteNetLib only)"), }; rootCommand.Name = "NetworkBenchmarkDotNet";