PK.GRPC.Utilities
1.0.1
dotnet add package PK.GRPC.Utilities --version 1.0.1
NuGet\Install-Package PK.GRPC.Utilities -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PK.GRPC.Utilities" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PK.GRPC.Utilities --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PK.GRPC.Utilities, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PK.GRPC.Utilities as a Cake Addin
#addin nuget:?package=PK.GRPC.Utilities&version=1.0.1
// Install PK.GRPC.Utilities as a Cake Tool
#tool nuget:?package=PK.GRPC.Utilities&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PK.GRPC.Utilities
简单封装的Grpc通用操作类库,为了更方便的使用它。
服务端简单示例:
class Program
{
private static GrpcServerHelper grpcServerHelper = new GrpcServerHelper(new GrpcRequestMessageHandler(), 5000);
static void Main(string[] args)
{
grpcServerHelper.Start();
Console.ReadKey();
grpcServerHelper.Dispose();
}
}
/// <summary>
/// 服务端请求消息处理者
/// </summary>
public class GrpcRequestMessageHandler : IGrpcMessageHandler
{
/// <summary>
/// 简单模式处理方法
/// </summary>
/// <param name="requestData"></param>
/// <param name="context"></param>
/// <returns></returns>
public async Task<string> Handle(string requestData, ServerCallContext context)
{
Console.WriteLine($"Client:{context.Peer}。简单模式接收数据:{requestData}");
return requestData;
}
public async Task<byte[]> MultiHandle(byte[] requestData, ServerCallContext context)
{
string data = Encoding.UTF8.GetString(requestData);
Console.WriteLine($"Client:{context.Peer}。双向流接收数据:{data}");
return requestData;
}
}
客户端简单示例:
class Program
{
private static GrpcClientFactoryHelper grpcClientFactoryHelper = new GrpcClientFactoryHelper("127.0.0.1:5000");
static void Main(string[] args)
{
var data = JObject.FromObject(new {@data = "测试简单模式"}).ToString();
var client = grpcClientFactoryHelper.Create();
var response = client.SendString(data);
Console.WriteLine(response);
Console.ReadKey();
//双向流测试
var bytes = Encoding.UTF8.GetBytes("START");
client = grpcClientFactoryHelper.Create(new GrpcMultiMessageHandler());
Console.WriteLine($"multi start at {DateTime.Now.ToString($"yyyy-MM-dd HH:mm:ss.fff")}");
client.StartMultiStreamAsync(bytes).Wait();
Console.WriteLine($"multi end at {DateTime.Now.ToString($"yyyy-MM-dd HH:mm:ss.fff")}");
Console.ReadKey();
grpcClientFactoryHelper.Dispose();
}
}
/// <summary>
/// 服务端请求消息处理者
/// </summary>
public class GrpcMultiMessageHandler : IGrpcMultiMessageHandler
{
private int receiveCount = 0;
public async Task<Tuple<byte[], bool>> MultiHandle(byte[] responseData, Metadata responseHeaders)
{
string data = Encoding.UTF8.GetString(responseData);
Console.WriteLine($"双向流接收数据:{data}");
receiveCount++;
if (data == "END")
{
return new Tuple<byte[], bool>(null, true);
}
if (receiveCount == 100)
{
return new Tuple<byte[], bool>(Encoding.UTF8.GetBytes("END"), false);
}
return new Tuple<byte[], bool>(Encoding.UTF8.GetBytes($"{receiveCount}"), false);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Google.Protobuf (>= 3.5.1)
- Grpc (>= 2.23.0)
- Grpc.Core (>= 2.23.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.