9swampy / Telnet

Published on Nuget at https://www.nuget.org/packages/Telnet

Home Page:http://www.nugetmusthaves.com/Package/Telnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TelnetServer not found

AndreasReitberger opened this issue · comments

Hi!
I tried your example code, however I cannot find the TelnetServer class. Or has this class been replaced with the TcpClient?

using (TelnetServer server = new TelnetServer())

Have you a working example? I have struggles to get the login work...
Thanks!

[TestMethod]
    public async Task ReadmeExample()
    {
      using (TelnetServer server = new TelnetServer())
      {
        using (Client client = new Client(server.IPAddress.ToString(), server.Port, new System.Threading.CancellationToken()))
        {
          client.IsConnected.Should().Be(true);
          (await client.TryLoginAsync("username", "password", TimeoutMs)).Should().Be(true);
          client.WriteLine("show statistic wan2");
          string s = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(TimeoutMs));
          s.Should().Contain(">");
          s.Should().Contain("WAN2");
          Regex regEx = new Regex("(?!WAN2 total TX: )([0-9.]*)(?! GB ,RX: )([0-9.]*)(?= GB)");
          regEx.IsMatch(s).Should().Be(true);
          MatchCollection matches = regEx.Matches(s);
          decimal tx = decimal.Parse(matches[0].Value);
          decimal rx = decimal.Parse(matches[1].Value);
          (tx + rx).Should().BeLessThan(50);
        }
      }
    }

The server doesn't come with the Nuget package. It's a simple mock class that's used in the Unit Tests you'll find in the GitHub code should you download that.. Point the client at the server you're wanting to Telnet to. If the canned login doesn't work it's likely you need a different line terminator or feed.

Hi,
yes in deed, it was the termination char! Got it working now. Thank you for your quick respone!