Updated
This commit is contained in:
1 parent
2c5b69bf2c
commit
22dee59f47
132 files changed
+19653
-7192
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using EonaCat.Connections.Models;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace EonaCat.Connections.Quic.Client.Example
|
||||
{
|
||||
[RequiresPreviewFeatures]
|
||||
public class Program
|
||||
{
|
||||
private const string SERVER_IP = "127.0.0.1";
|
||||
private const int SERVER_PORT = 8443;
|
||||
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var config = new Configuration
|
||||
{
|
||||
Host = SERVER_IP,
|
||||
Port = SERVER_PORT,
|
||||
IsSelfSignedEnabled = true,
|
||||
EnableAutoReconnect = true,
|
||||
ReconnectDelayInSeconds = 5,
|
||||
};
|
||||
|
||||
await using var client = new QuicNetworkClient(config);
|
||||
|
||||
client.OnConnected += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[QUIC Client] Connected to {e.RemoteEndPoint}");
|
||||
};
|
||||
|
||||
client.OnDataReceived += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[QUIC Client] Received: {e.StringData}");
|
||||
};
|
||||
|
||||
client.OnDisconnected += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[QUIC Client] Disconnected: {e.Reason}");
|
||||
};
|
||||
|
||||
client.OnGeneralError += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[QUIC Client] Error: {e.Message} - {e.Exception?.Message}");
|
||||
};
|
||||
|
||||
Console.WriteLine("[QUIC Client] Connecting...");
|
||||
var connected = await client.ConnectAsync();
|
||||
|
||||
if (!connected)
|
||||
{
|
||||
Console.WriteLine("[QUIC Client] Failed to connect. Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
|
||||
await client.SendNicknameAsync("QuicTestClient");
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.Write("Enter message (or 'exit'): ");
|
||||
var message = Console.ReadLine();
|
||||
|
||||
if (string.IsNullOrEmpty(message) || message.Equals("exit", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await client.SendAsync(message);
|
||||
}
|
||||
|
||||
await client.DisconnectAsync();
|
||||
Console.WriteLine("[QUIC Client] Disconnected. Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user