Skip to content

Commit

Permalink
Add option to for native sockets commandline arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDeml committed Apr 3, 2023
1 parent b0834d6 commit a63e20e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
8 changes: 8 additions & 0 deletions NetworkBenchmarkDotNet/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public class Configuration
/// </summary>
public int ServerTickRate { get; set; }

/// <summary>
/// Special feature of LiteNetLib for using faster socket implementation
/// This is currently not supported for all platforms
/// </summary>
public bool UseNativeSockets { get; set; }

public byte[] Message { get; private set; }

public void PrepareForNewBenchmark()
Expand Down Expand Up @@ -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)
Expand All @@ -225,6 +232,7 @@ public static void ApplyPredefinedBenchmarkConfiguration(Configuration config)
config.MessageByteSize = 32;
config.ServerTickRate = 60;
config.ClientTickRate = 60;
config.UseNativeSockets = true;
}
}
}
8 changes: 3 additions & 5 deletions NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@ 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)
{
this.id = id;
this.config = config;
this.benchmarkStatistics = benchmarkStatistics;
deliveryMethod = LiteNetLibBenchmark.GetDeliveryMethod(config.Transmission);

netManager = new NetManager(this);
if (!config.Address.Contains(':'))
{
netManager.IPv6Mode = IPv6Mode.Disabled;
}

//netManager.UseNativeSockets = true;
netManager.UseNativeSockets = config.UseNativeSockets;
netManager.UpdateTime = Utilities.CalculateTimeout(config.ClientTickRate);
netManager.UnsyncedEvents = true;
netManager.DisconnectTimeout = 10000;
Expand Down Expand Up @@ -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();
}
}
Expand Down
4 changes: 1 addition & 3 deletions NetworkBenchmarkDotNet/Libraries/LiteNetLib/EchoServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion NetworkBenchmarkDotNet/Utils/CommandLineUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public static RootCommand GenerateRootCommand()
new Option<int>(
"--server-tick-rate",
getDefaultValue: () => 60,
"Server ticks per second if supported")
"Server ticks per second if supported"),
new Option<bool>(
"--use-native-sockets",
getDefaultValue: () => true,
"Use native Sockets (LiteNetLib only)"),
};

rootCommand.Name = "NetworkBenchmarkDotNet";
Expand Down

0 comments on commit a63e20e

Please sign in to comment.