Skip to content

Commit

Permalink
Simple Echo Example.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryCordewener committed Jan 4, 2024
1 parent e9209c0 commit d4578c1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions TelnetNegotiationCore.TestServer/KestrelMockServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ public Task SignalMSSPAsync(MSSPConfig val) =>
public Task SignalNAWSAsync(int height, int width) =>
Task.Run(() => _Logger.Debug("Client Height and Width updated: {Height}x{Width}", height, width));

public static Task WriteBackAsync(byte[] writeback, Encoding encoding) =>
Task.Run(() => Console.WriteLine(encoding.GetString(writeback)));
public static async Task WriteBackAsync(byte[] writeback, Encoding encoding, PipeWriter writer)
{
var str = encoding.GetString(writeback);
if (str.StartsWith("echo"))
{
await writer.WriteAsync(encoding.GetBytes($"We heard: {str}" + Environment.NewLine));
}
Console.WriteLine(encoding.GetString(writeback));
}

public async override Task OnConnectedAsync(ConnectionContext connection)
{
_Logger.Information(connection.ConnectionId + " connected");

var telnet = await new TelnetInterpreter(TelnetInterpreter.TelnetMode.Server, _Logger.ForContext<TelnetInterpreter>())
var telnet = await new TelnetInterpreter(TelnetInterpreter.TelnetMode.Server)
{
CallbackOnSubmitAsync = WriteBackAsync,
CallbackOnSubmitAsync = (w,e) => WriteBackAsync(w,e, connection.Transport.Output),
SignalOnGMCPAsync = SignalGMCPAsync,
SignalOnMSSPAsync = SignalMSSPAsync,
SignalOnNAWSAsync = SignalNAWSAsync,
Expand Down

0 comments on commit d4578c1

Please sign in to comment.