Initial version
This commit is contained in:
14
EonaCat.Connections.Client/EonaCat.Connections.Client.csproj
Normal file
14
EonaCat.Connections.Client/EonaCat.Connections.Client.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EonaCat.Connections\EonaCat.Connections.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
64
EonaCat.Connections.Client/Program.cs
Normal file
64
EonaCat.Connections.Client/Program.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using EonaCat.Connections;
|
||||
using EonaCat.Connections.Models;
|
||||
|
||||
namespace EonaCat.Connections.Client.Example
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static NetworkClient _client;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateClientAsync().ConfigureAwait(false);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.Write("Enter message to send (or 'exit' to quit): ");
|
||||
var message = Console.ReadLine();
|
||||
if (!string.IsNullOrEmpty(message) && message.Equals("exit", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_client.DisconnectAsync().ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
_client.SendAsync(message).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task CreateClientAsync()
|
||||
{
|
||||
var config = new Configuration
|
||||
{
|
||||
Protocol = ProtocolType.TCP,
|
||||
Host = "127.0.0.1",
|
||||
Port = 8080,
|
||||
UseSsl = true,
|
||||
UseAesEncryption = true,
|
||||
ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("client.pfx", "p@ss"),
|
||||
};
|
||||
|
||||
_client = new NetworkClient(config);
|
||||
|
||||
// Subscribe to events
|
||||
_client.OnConnected += (sender, e) =>
|
||||
Console.WriteLine($"Connected to server at {e.RemoteEndPoint}");
|
||||
|
||||
_client.OnDataReceived += (sender, e) =>
|
||||
Console.WriteLine($"Server says: {(e.IsBinary ? $"{e.Data.Length} bytes" : e.StringData)}");
|
||||
|
||||
_client.OnDisconnected += (sender, e) =>
|
||||
Console.WriteLine("Disconnected from server");
|
||||
|
||||
await _client.ConnectAsync();
|
||||
|
||||
// Send nickname
|
||||
await _client.SendNicknameAsync("TestUser");
|
||||
|
||||
// Send a message
|
||||
await _client.SendAsync("Hello server!");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user