ZayniFramework.Middle.TelnetService
2.2.3
See the version list below for details.
dotnet add package ZayniFramework.Middle.TelnetService --version 2.2.3
NuGet\Install-Package ZayniFramework.Middle.TelnetService -Version 2.2.3
<PackageReference Include="ZayniFramework.Middle.TelnetService" Version="2.2.3" />
paket add ZayniFramework.Middle.TelnetService --version 2.2.3
#r "nuget: ZayniFramework.Middle.TelnetService, 2.2.3"
// Install ZayniFramework.Middle.TelnetService as a Cake Addin
#addin nuget:?package=ZayniFramework.Middle.TelnetService&version=2.2.3
// Install ZayniFramework.Middle.TelnetService as a Cake Tool
#tool nuget:?package=ZayniFramework.Middle.TelnetService&version=2.2.3
Middle.TelnetService example.
The Middle.TelnetService and Common module provide the API of ICommand, ConsoleCommand and RemoteCommand for your application. You can use it to build a telnet service to receive the remote telnet command from any telent client very easily!
Add namespace using.
using ZayniFramework.Common;
using ZayniFramework.Middle.TelnetService;
Write your ConsoleCommand class and extends the ConsoleCommand base class.
public sealed class YourConsoleCommand : ConsoleCommand
{
/// <summary>Execute the command.
/// </summary>
public override void ExecuteCommand()
{
// Implement your code here...
Result.Success = true;
}
}
Write your telnet RemoteCommand class and extends the RemoteCommand base class.
public class YourRemoteCommand : RemoteCommand
{
/// <summary>Execute the command.
/// </summary>
public override void ExecuteCommand()
{
// Implement your code here...
Result.Success = r.Success;
}
}
Then, you have to register your ICommand object to the CommandContainer. Like this,
private static CommandContainer RegisterCommands()
{
var commandContainer = new CommandContainer();
commandContainer.RegisterCommand<YourConsoleCommand>( "the command name 1", commandText => 0 == string.Compare( commandText, "some command line", true ) );
commandContainer.RegisterCommand<YourRemoteCommand>( "the command name 12", commandText => 0 == string.Compare( commandText, "some command line", true ) );
commandContainer.RegisterCommand<ClearConsoleCommand>( "cls", commandText => 0 == string.Compare( commandText, "cls", true ) );
commandContainer.RegisterUnknowCommand<UnknowRemoteCommand>();
return commandContainer;
}
Start to process to receive the console command in your application. And create a TelnetServer, then start the telnet service.
private static void ProcessConsoleCommand( CommandContainer container )
{
while ( true )
{
string commandText = null;
try
{
commandText = Console.ReadLine();
if ( commandText.IsNullOrEmpty() )
{
continue;
}
var command = container.Get<ConsoleCommand>( commandText );
if ( command.IsNull() )
{
continue;
}
command.Command = commandText;
command.Execute();
}
catch ( Exception ex )
{
Logger.WriteExceptionLog( nameof ( Program ), ex, $"Process console command occur exception. Console command: {commandText}. {Environment.NewLine}{ex.ToString()}" );
continue;
}
}
}
private static void StartTelnetService( CommandContainer commandContainer )
{
if ( !ConfigManagement.AppSettings.ContainsKey( "TelnetServerPort" ) )
{
return;
}
var strPort = ConfigManagement.AppSettings[ "TelnetServerPort" ];
if ( strPort.IsNullOrEmpty() || !int.TryParse( strPort, out int port ) || port <= 0 )
{
return;
}
var password = ConfigManagement.AppSettings.ContainsKey( "TelnetServerPassword" ) ? ConfigManagement.AppSettings[ "TelnetServerPassword" ] : null;
var telnetService = new TelnetServer( port, password );
telnetService.StartService( ( reader, writer, client ) => ProcessTelnetCommand( reader, writer, client, commandContainer ) );
Console.WriteLine( $"Start telnet server success. Listen tcp port on {strPort}." );
}
private static void ProcessTelnetCommand( StreamReader reader, StreamWriter writer, TcpClient tcpClient, CommandContainer container )
{
if ( reader.IsNull() || writer.IsNull() || !tcpClient.Connected )
{
return;
}
if ( !reader.BaseStream.CanRead || !writer.BaseStream.CanWrite )
{
return;
}
while ( true )
{
try
{
if ( !reader.BaseStream.CanRead || !writer.BaseStream.CanWrite )
{
break;
}
var commandText = reader.ReadLine();
var command = container.Get<RemoteCommand>( commandText );
if ( command.IsNull() )
{
continue;
}
command.Command = commandText;
command.StreamReader = reader;
command.StreamWriter = writer;
command.TelnetClient = tcpClient;
command.Execute();
}
catch ( Exception ex )
{
Logger.WriteExceptionLog( nameof ( Program ), ex, $"Process telnet command occur exception. {Environment.NewLine}{ex.ToString()}" );
continue;
}
}
}
Finally, you can start the console command and telnet remote command service to receive the commands. Like this.
var commandContainer = RegisterCommands();
StartTelnetService( commandContainer );
ProcessConsoleCommand( commandContainer );
More detail and sample. You can go to the Test/ServiceHostTest/ServiceHost.Client.App directory.
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. |
-
.NETStandard 2.0
- ZayniFramework.Common (>= 2.2.2)
- ZayniFramework.Logging (>= 2.2.1)
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 |
---|---|---|
8.0.142 | 121 | 3/19/2024 |
8.0.141 | 146 | 1/4/2024 |
8.0.140 | 98 | 12/17/2023 |
6.0.138 | 96 | 3/19/2024 |
6.0.137 | 156 | 9/20/2023 |
6.0.136 | 129 | 9/14/2023 |
6.0.135 | 129 | 9/10/2023 |
6.0.134 | 143 | 7/12/2023 |
6.0.133 | 144 | 7/10/2023 |
6.0.132 | 148 | 7/7/2023 |
6.0.131 | 151 | 6/19/2023 |
6.0.130 | 152 | 6/19/2023 |
6.0.129 | 10,161 | 7/2/2022 |
6.0.128 | 522 | 1/16/2022 |
6.0.127 | 476 | 1/15/2022 |
6.0.126 | 453 | 1/15/2022 |
6.0.125 | 310 | 1/8/2022 |
6.0.125-hotfix1 | 188 | 1/8/2022 |
6.0.124 | 304 | 1/7/2022 |
6.0.123 | 411 | 11/14/2021 |
5.0.129 | 548 | 7/2/2022 |
5.0.128 | 516 | 1/16/2022 |
5.0.125 | 313 | 1/8/2022 |
5.0.124 | 294 | 1/7/2022 |
5.0.123 | 438 | 11/14/2021 |
5.0.122 | 498 | 10/11/2021 |
5.0.121 | 527 | 5/1/2021 |
3.1.137 | 124 | 9/20/2023 |
3.1.136 | 111 | 9/14/2023 |
3.1.135 | 115 | 9/10/2023 |
3.1.134 | 155 | 7/12/2023 |
3.1.133 | 144 | 7/11/2023 |
3.1.132 | 139 | 7/8/2023 |
3.1.131 | 150 | 6/19/2023 |
3.1.130 | 295 | 2/1/2023 |
3.1.129 | 500 | 7/2/2022 |
3.1.128 | 468 | 1/16/2022 |
3.1.125 | 271 | 1/8/2022 |
3.1.124 | 264 | 1/7/2022 |
3.1.123 | 434 | 11/14/2021 |
3.1.122 | 472 | 10/11/2021 |
3.1.121 | 486 | 5/1/2021 |
2.31.120 | 413 | 3/14/2021 |
2.30.115 | 3,274 | 3/6/2021 |
2.30.114 | 379 | 3/6/2021 |
2.20.101 | 1,085 | 3/1/2021 |
2.19.3 | 473 | 2/11/2021 |
2.19.2 | 10,049 | 2/6/2021 |
2.19.1 | 630 | 1/6/2021 |
2.19.0 | 605 | 1/1/2021 |
2.18.3 | 530 | 12/27/2020 |
2.18.2 | 1,314 | 8/29/2020 |
2.18.1 | 508 | 8/26/2020 |
2.18.0 | 4,786 | 8/20/2020 |
2.17.135 | 534 | 8/19/2020 |
2.17.134 | 559 | 7/28/2020 |
2.17.133 | 608 | 7/27/2020 |
2.17.132 | 600 | 7/18/2020 |
2.17.131 | 800 | 7/11/2020 |
2.16.130 | 730 | 6/13/2020 |
2.15.128 | 622 | 6/3/2020 |
2.15.127 | 618 | 5/31/2020 |
2.15.126 | 1,438 | 4/30/2020 |
2.14.122 | 615 | 4/13/2020 |
2.13.100 | 639 | 3/12/2020 |
2.12.51 | 693 | 2/18/2020 |
2.11.50 | 600 | 2/10/2020 |
2.10.44 | 656 | 1/30/2020 |
2.9.43 | 819 | 1/11/2020 |
2.8.42 | 638 | 1/10/2020 |
2.8.41 | 665 | 1/5/2020 |
2.7.40 | 715 | 1/2/2020 |
2.7.39 | 647 | 1/2/2020 |
2.7.38 | 717 | 1/1/2020 |
2.6.37 | 667 | 12/23/2019 |
2.6.35 | 846 | 12/4/2019 |
2.6.1 | 620 | 12/2/2019 |
2.6.0 | 607 | 11/28/2019 |
2.5.2 | 807 | 11/26/2019 |
2.5.1 | 723 | 11/12/2019 |
2.5.0 | 586 | 11/9/2019 |
2.4.3 | 777 | 10/16/2019 |
2.4.2 | 663 | 10/16/2019 |
2.4.1 | 777 | 9/20/2019 |
2.3.113 | 424 | 3/6/2021 |
2.3.112 | 430 | 3/6/2021 |
2.3.28 | 636 | 9/19/2019 |
2.3.27 | 821 | 8/30/2019 |
2.3.26 | 772 | 8/20/2019 |
2.3.25 | 654 | 8/12/2019 |
2.3.22 | 664 | 7/31/2019 |
2.3.21 | 837 | 7/20/2019 |
2.3.20 | 754 | 6/22/2019 |
2.3.19 | 648 | 6/14/2019 |
2.3.18 | 688 | 6/13/2019 |
2.3.17 | 666 | 6/13/2019 |
2.3.15 | 668 | 6/8/2019 |
2.3.14 | 645 | 6/8/2019 |
2.3.13 | 683 | 5/30/2019 |
2.3.12 | 591 | 5/24/2019 |
2.3.11 | 601 | 5/24/2019 |
2.3.10 | 602 | 5/21/2019 |
2.3.9 | 600 | 5/9/2019 |
2.3.8 | 598 | 5/8/2019 |
2.3.7 | 650 | 4/30/2019 |
2.3.6 | 716 | 4/23/2019 |
2.3.5 | 632 | 4/19/2019 |
2.3.4 | 593 | 4/18/2019 |
2.3.3 | 620 | 4/17/2019 |
2.3.2 | 620 | 4/6/2019 |
2.3.1 | 725 | 12/15/2018 |
2.3.0 | 688 | 12/7/2018 |
2.2.6 | 727 | 11/25/2018 |
2.2.5 | 730 | 11/23/2018 |
2.2.3 | 752 | 11/20/2018 |
2.2.2 | 745 | 11/19/2018 |
2.2.1 | 759 | 11/17/2018 |
1.1.0 | 804 | 11/15/2018 |
1.0.1 | 717 | 11/6/2018 |
1.0.0 | 767 | 11/4/2018 |