Skip to content

Commit

Permalink
Small updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryCordewener committed Jan 3, 2024
1 parent 6bfbc20 commit 2d29cd2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ At this time, this repository is in a rough state and does not yet implement som
| http://www.faqs.org/rfcs/rfc2946.html | Encryption Negotiation | No | Rejects |

## ANSI Support, ETC?
Being a Telnet Negotiation Library, this library doesn't give support for extensions like ANSI, Pueblo, MXP, etc at this time.

# Todo
* Create a Changelog
* Use Github Actions to create Nuget Package
Being a Telnet Negotiation Library, this library doesn't give support for extensions like ANSI, Pueblo, MXP, etc at this time.
26 changes: 19 additions & 7 deletions TelnetNegotiationCore.TestClient/MockClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,37 @@ public class MockClient

public MockClient(string ip, int port, ILogger? logger = null)
{
Console.OutputEncoding = Encoding.UTF8;
Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8;

_Logger = logger ?? Log.Logger.ForContext<MockClient>();
IPAddress localAddress = IPAddress.Parse(ip);
client = new TcpClient(localAddress.ToString(), port);
}


public void Start()
{
var t = new Thread(new ParameterizedThreadStart(Handle));
t.Start(client);

while (true)
{
var read = Console.ReadLine() + "\n\r";
var read = Console.ReadLine() + "\n\r";
telnet?.SendPromptAsync(telnet?.CurrentEncoding.GetBytes(read)).GetAwaiter().GetResult();
}
}

private static async Task WriteToOutputStream(byte[] arg, StreamWriter writer) => await writer.BaseStream.WriteAsync(arg, CancellationToken.None);

public static Task WriteBack(byte[] writeback, Encoding encoding)
private async Task WriteToOutputStream(byte[] arg, StreamWriter writer)
{
try {
await writer.BaseStream.WriteAsync(arg, CancellationToken.None);
}
catch(ObjectDisposedException ode)
{
_Logger.Information("Stream has been closed", ode);
}
}

public Task WriteBack(byte[] writeback, Encoding encoding)
{
string str = encoding.GetString(writeback);
Console.WriteLine(str);
Expand Down Expand Up @@ -63,7 +75,7 @@ public void Handle(object? obj)

using var stream = client.GetStream();
using var input = new StreamReader(stream);
using var output = new StreamWriter(stream) { AutoFlush = true };
using var output = new StreamWriter(stream, leaveOpen: true) { AutoFlush = true };

telnet = new TelnetInterpreter(TelnetInterpreter.TelnetMode.Client, _Logger.ForContext<TelnetInterpreter>())
{
Expand Down
5 changes: 3 additions & 2 deletions TelnetNegotiationCore.TestClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ static void Main()
{
var log = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File(new CompactJsonFormatter(), "logresult.log")
.WriteTo.Console()
.MinimumLevel.Debug()
.CreateLogger();

Log.Logger = log;
var _ = new MockClient("127.0.0.1", 4201, log.ForContext<MockClient>());
var client = new MockClient("127.0.0.1", 4201, log.ForContext<MockClient>());
client.Start();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down

0 comments on commit 2d29cd2

Please sign in to comment.