telnet samples
This commit is contained in:
44
MySolution/ConsoleApp/TelnetSamples/TelnetConsole.cs
Normal file
44
MySolution/ConsoleApp/TelnetSamples/TelnetConsole.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Samples.Telnet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp.TelnetSamples
|
||||
{
|
||||
internal class TelnetConsole
|
||||
{
|
||||
private static ITelnetClient _client;
|
||||
|
||||
public TelnetConsole(ITelnetClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public void Start(string ip, int port = 23)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write(_client.Connect(ip, port));
|
||||
|
||||
while (true)
|
||||
{
|
||||
string command = Console.ReadLine();
|
||||
if (command == "quit" || command == "exit")
|
||||
break;
|
||||
|
||||
Console.Write(_client.SendCommand(command));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_client.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user