JSSoft.Communication 2.0.3-pr.31

This is a prerelease version of JSSoft.Communication.
There is a newer version of this package available.
See the version list below for details.
dotnet add package JSSoft.Communication --version 2.0.3-pr.31                
NuGet\Install-Package JSSoft.Communication -Version 2.0.3-pr.31                
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="JSSoft.Communication" Version="2.0.3-pr.31" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JSSoft.Communication --version 2.0.3-pr.31                
#r "nuget: JSSoft.Communication, 2.0.3-pr.31"                
#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 JSSoft.Communication as a Cake Addin
#addin nuget:?package=JSSoft.Communication&version=2.0.3-pr.31&prerelease

// Install JSSoft.Communication as a Cake Tool
#tool nuget:?package=JSSoft.Communication&version=2.0.3-pr.31&prerelease                

Communication

NuGet NuGet (prerelease)

Summary

The Communication library is network module using https://github.com/grpc/grpc.

Development Environment

.NET 8.0
c# 12.0

Clone

git clone https://github.com/s2quake/communication.git
cd communication

Build

dotnet build

Run server

dotnet run --project src/JSSoft.Communication.Server

Run client

dotnet run --project src/JSSoft.Communication.Client

Quick start

1. Create solution

Run terminal and execute the command line below to create a solution and project

mkdir .example
dotnet new sln -o .example
dotnet new console -o .example/Server-Test
dotnet new console -o .example/Client-Test
dotnet sln .example add .example/Server-Test
dotnet sln .example add .example/Client-Test
dotnet add .example/Server-Test reference src/JSSoft.Communication
dotnet add .example/Client-Test reference src/JSSoft.Communication

2. Define service

Create IMyService.cs file in the path .example/Server-Test.

Then copy and paste the code below into the file IMyService.cs.

namespace Services;

public interface IMyService
{
    Task<Guid> LoginAsync(string userID, CancellationToken cancellationToken);

    Task<(string product, string version)> GetVersionAsync(CancellationToken cancellationToken);
}

3. Implement service

Create MyService.cs file in the path .example/Server-Test.

Then copy and paste the code below into the file MyService.cs.

using JSSoft.Communication;

namespace Services;

sealed class MyService : ServerService<IMyService>, IMyService
{
    public Task<Guid> LoginAsync(string userID, CancellationToken cancellationToken)
    {
        return Task.Run(() => 
        {
            Console.WriteLine($"logged in: '{userID}'");
            return Guid.NewGuid();
        }, cancellationToken);
    }

    public Task<(string product, string version)> GetVersionAsync(CancellationToken cancellationToken)
    {
        return Task.Run(() =>
        {
            return ("MyServer", "1.0.0.0");
        }, cancellationToken);
    }
}

4. Implement code to run the server

Create Program.cs file in the path .example/Server-Test.

Then copy and paste the code below into the file Program.cs.

using JSSoft.Communication;
using JSSoft.Communication.Extensions;
using Services;

var service = new MyService();
var serviceContext = new ServerContext([service]);
var token = await serviceContext.OpenAsync(cancellationToken: default);

Console.WriteLine("Server has been started.");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();

var exitCode = await serviceContext.ReleaseAsync(token);
Environment.Exit(exitCode);

5. Implement code to run the client

First, you need to include the file IMyService.cs that you created when you created the Server-Test project.

Open .example/Client-Test/Client-Test.csproj and insert <Compile Include="..\Server-Test\IMyService.cs" /> into the file as shown below.

...
  <ItemGroup>
    <ProjectReference Include="..\..\src\JSSoft.Communication\JSSoft.Communication.csproj" />
    
    <Compile Include="..\Server-Test\IMyService.cs" />
  </ItemGroup>
...

And create Program.cs file in the path .example/Server-Test.

Then copy and paste the code below into the file Program.cs.

using JSSoft.Communication;
using JSSoft.Communication.Extensions;
using Services;

var service = new ClientService<IMyService>();
var serviceContext = new ClientContext([service]);

var token = await serviceContext.OpenAsync(cancellationToken: default);
var server = service.Server;

var id = await server.LoginAsync("admin", cancellationToken: default);
var (product, version) = await server.GetVersionAsync(cancellationToken: default);
Console.WriteLine($"logged in: {id}");
Console.WriteLine($"product: {product}");
Console.WriteLine($"version: {version}");

Console.WriteLine("Press any key to exit.");
Console.ReadKey();

var exitCode = await serviceContext.ReleaseAsync(token);
Environment.Exit(exitCode);

6. Build and Run example

Build example solution

dotnet build .example

Run Server-Test example project in terminal

dotnet run --project .example/Server-Test

Run Client-Test example project in a new terminal

dotnet run --project .example/Client-Test
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.6 276 6/30/2024
2.0.6-pr.35 51 6/30/2024
2.0.6-pr.34 56 6/30/2024
2.0.5 99 6/30/2024
2.0.5-pr.34 46 6/30/2024
2.0.3-pr.33 51 6/30/2024
2.0.3-pr.32 48 6/30/2024
2.0.3-pr.31 44 6/30/2024
2.0.3-pr.30 54 6/30/2024
2.0.3-pr.29 55 6/29/2024
2.0.3-pr.28 51 6/29/2024
2.0.3-pr.27 49 6/29/2024
2.0.3-pr.26 51 6/29/2024
2.0.2 113 6/16/2024
2.0.1 115 6/4/2024
2.0.0 106 6/1/2024