Overview
This article will demonstrate how to use RLogin in .NET using Telnet Factory for .NET.
Code Example
Download TelnetLicense.txt
| Download RL.cs | Download RL.vb
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Jscape.Telnet;
5: using Jscape.Telnet.Options;
6:
7: namespace RLogin_NET
8: {
9: class RL
10: {
11: Rlogin rl = null;
12: public RL()
13: {
14: rl = new Rlogin();
15: rl.LicenseKey = null; // copy license key here
16: rl.ConnectedEvent +=
17: new Rlogin.RloginConnectedEventHandler(OnConnected);
18: rl.DataReceivedEvent +=
19: new Rlogin.RloginDataReceivedEventHandler(OnDataReceived);
20: }
21:
22: public void openConnection(string hostname, string username)
23: {
24: rl.Connect(hostname, username);
25: }
26:
27: public void closeConnection()
28: {
29: rl.Disconnect();
30: }
31:
32: public void Send(string data)
33: {
34: rl.Send(data + "\r\n");
35: }
36:
37: public void OnDataReceived(object sender, RloginDataReceivedEventArgs e)
38: {
39: byte[] buffer = e.Data;
40: string data = rl.Encoding.GetString(buffer);
41: Console.Write(data);
42: }
43:
44: public void OnConnected(object sender, RloginConnectedEventArgs e)
45: {
46: Console.WriteLine("Connected.");
47: }
48:
49: static void Main(string[] args)
50: {
51: try
52: {
53: RL rl = new RL();
54: rl.openConnection("host", "user");
55: rl.closeConnection();
56: }
57: catch (Exception e)
58: {
59: Console.WriteLine(e.Message);
60: }
61:
62: Console.WriteLine("Press any key to continue ... ");
63: Console.Read();
64: }
65: }
66: }
Lines 1-5 : Necessary import statements.
Lines 11-20 : Initialize RLogin instance and connect event handlers.
Lines 22-30 : Methods for opening and closing connection to the server.
Lines 32-35 : Send data to the server.
Lines 37-42 : Event handler for receiving data.
Lines 44-47 : Event handler for connected event.
Line 53 : Initialize RL instance.
Comments