Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TelnetServer not found #40

Closed
AndreasReitberger opened this issue Jan 31, 2019 · 2 comments
Closed

TelnetServer not found #40

AndreasReitberger opened this issue Jan 31, 2019 · 2 comments

Comments

@AndreasReitberger
Copy link

AndreasReitberger commented Jan 31, 2019

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);
        }
      }
    }
@9swampy
Copy link
Owner

9swampy commented Jan 31, 2019 via email

@AndreasReitberger
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants