Updated
This commit is contained in:
1 parent
2c5b69bf2c
commit
22dee59f47
132 files changed
+19653
-7192
No files matched your search
@@ -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.gRPC\EonaCat.Connections.gRPC.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,73 @@
|
||||
using EonaCat.Connections.Models;
|
||||
|
||||
namespace EonaCat.Connections.gRPC.Client.Example
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private const string SERVER_IP = "127.0.0.1";
|
||||
private const int SERVER_PORT = 5443;
|
||||
|
||||
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 GrpcNetworkClient(config);
|
||||
|
||||
client.OnConnected += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[gRPC Client] Connected to {e.RemoteEndPoint}");
|
||||
};
|
||||
|
||||
client.OnDataReceived += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[gRPC Client] Received: {e.StringData}");
|
||||
};
|
||||
|
||||
client.OnDisconnected += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[gRPC Client] Disconnected: {e.Reason}");
|
||||
};
|
||||
|
||||
client.OnGeneralError += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"[gRPC Client] Error: {e.Message} - {e.Exception?.Message}");
|
||||
};
|
||||
|
||||
Console.WriteLine("[gRPC Client] Connecting...");
|
||||
var connected = await client.ConnectAsync();
|
||||
|
||||
if (!connected)
|
||||
{
|
||||
Console.WriteLine("[gRPC Client] Failed to connect. Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
|
||||
await client.SendNicknameAsync("GrpcTestClient");
|
||||
|
||||
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("[gRPC Client] Disconnected. Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user