Added client title counter in example
This commit is contained in:
parent
c7df4ab7a2
commit
1a15416613
|
@ -9,7 +9,10 @@ namespace EonaCat.Connections.Client.Example
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
CreateClientAsync().ConfigureAwait(false);
|
for (int i = 0; i < 100000; i++)
|
||||||
|
{
|
||||||
|
CreateClientAsync(i).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +31,7 @@ namespace EonaCat.Connections.Client.Example
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task CreateClientAsync()
|
private static async Task CreateClientAsync(int i)
|
||||||
{
|
{
|
||||||
var config = new Configuration
|
var config = new Configuration
|
||||||
{
|
{
|
||||||
|
@ -55,7 +58,7 @@ namespace EonaCat.Connections.Client.Example
|
||||||
await _client.ConnectAsync();
|
await _client.ConnectAsync();
|
||||||
|
|
||||||
// Send nickname
|
// Send nickname
|
||||||
await _client.SendNicknameAsync("TestUser");
|
await _client.SendNicknameAsync($"TestUser{i}");
|
||||||
|
|
||||||
// Send a message
|
// Send a message
|
||||||
await _client.SendAsync("Hello server!");
|
await _client.SendAsync("Hello server!");
|
||||||
|
|
|
@ -43,13 +43,18 @@ namespace EonaCat.Connections.Server.Example
|
||||||
};
|
};
|
||||||
|
|
||||||
_server = new NetworkServer(config);
|
_server = new NetworkServer(config);
|
||||||
|
int totalClients = 0;
|
||||||
// Subscribe to events
|
// Subscribe to events
|
||||||
_server.OnConnected += (sender, e) =>
|
_server.OnConnected += (sender, e) =>
|
||||||
|
{
|
||||||
Console.WriteLine($"Client {e.ClientId} connected from {e.RemoteEndPoint}");
|
Console.WriteLine($"Client {e.ClientId} connected from {e.RemoteEndPoint}");
|
||||||
|
Console.Title = $"Active Connections: {++totalClients}";
|
||||||
|
};
|
||||||
|
|
||||||
_server.OnConnectedWithNickname += (sender, e) =>
|
_server.OnConnectedWithNickname += (sender, e) =>
|
||||||
|
{
|
||||||
Console.WriteLine($"Client {e.ClientId} connected with nickname: {e.Nickname}");
|
Console.WriteLine($"Client {e.ClientId} connected with nickname: {e.Nickname}");
|
||||||
|
};
|
||||||
|
|
||||||
_server.OnDataReceived += async (sender, e) =>
|
_server.OnDataReceived += async (sender, e) =>
|
||||||
{
|
{
|
||||||
|
@ -67,7 +72,10 @@ namespace EonaCat.Connections.Server.Example
|
||||||
};
|
};
|
||||||
|
|
||||||
_server.OnDisconnected += (sender, e) =>
|
_server.OnDisconnected += (sender, e) =>
|
||||||
|
{
|
||||||
Console.WriteLine($"Client {e.ClientId} disconnected");
|
Console.WriteLine($"Client {e.ClientId} disconnected");
|
||||||
|
Console.Title = $"Active Connections: {--totalClients}";
|
||||||
|
};
|
||||||
|
|
||||||
await _server.StartAsync();
|
await _server.StartAsync();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue