/// <summary> /// Connects to the mud server. Requires that the event handlers for required events be passed in here where they will /// be wired up. /// </summary> public async void Connect(EventHandler <string> lineReceived, EventHandler <string> dataReceived, EventHandler connectionClosed) { try { if (Telnet != null) { Telnet.Dispose(); Telnet = null; } Conveyor.EchoLog($"Connecting: {App.Settings.ProfileSettings.IpAddress}:{App.Settings.ProfileSettings.Port}", LogType.Information); var ctc = new CancellationTokenSource(); Telnet = new TelnetClient(App.Settings.ProfileSettings.IpAddress, App.Settings.ProfileSettings.Port, TimeSpan.FromSeconds(0), ctc.Token); Telnet.ConnectionClosed += connectionClosed; Telnet.LineReceived += lineReceived; Telnet.DataReceived += dataReceived; await Telnet.Connect(); } catch (Exception ex) { Telnet.Dispose(); Conveyor.EchoLog($"Connection Failed: {ex.Message}", LogType.Error); } }
public void ConnectClient() { TelClient = new TelnetClient(Host, Port, TimeSpan.Zero, CancelToken); TelClient.Connect().Wait(); TelClient.ConnectionClosed += OnConnectionClosed; TelClient.MessageReceived += OnMessageReceived; }
public void ConnectTest() { TelnetClient client = new TelnetClient(); client.Connect("127.0.0.1", 5402); Assert.AreEqual(true, client.IsConnected()); }
static void Main(string[] args) { TelnetClient tc = new TelnetClient(); //tc.ConnectionCheckingProc = null; Console.Write("Address: "); string a = "10.0.0.4"; // Console.ReadLine(); Console.Write("Port: "); string p = "23"; // Console.ReadLine(); Console.Write("Login: "******"admin"; // Console.ReadLine(); Console.Write("Passw: "); string pwd = "admin"; // Console.ReadLine(); bool res = tc.Connect( a, string.IsNullOrEmpty(p) ? 23 : int.Parse(p), string.IsNullOrEmpty(l) ? null : l, string.IsNullOrEmpty(pwd) ? null : pwd ); Console.WriteLine("Connection Result: {0}", res); string msg = ""; if (res) { while (msg != "exit") { Console.Write(tc.ReadToEnd() + " "); if (!tc.SendLine(msg = Console.ReadLine())) { Console.WriteLine(" *** error ***"); } } } Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); }
public ReturnObject Run(int planet) { Planet = planet; // Creates a telnet connection to NASA's Horizons database, on port 6775. telnetClient = new TelnetClient("horizons.jpl.nasa.gov", 6775, TimeSpan.FromSeconds(5), default(CancellationToken)); // Event handler methods are setup for the Telnet connection being closed and for a message being received. telnetClient.ConnectionClosed += HandleConnectionClosed; telnetClient.MessageReceived += HandleMessageReceived; // This starts the Telnet connection. telnetClient.Connect(); // Wait until completed. while (!Done) { continue; } return(RetVal); }
private void ConnectToServer(string ip, int port, TimeSpan delay) { if (_serverData.TelnetState != TelnetState.disconnected) { DisconnectFromServer(); } Logger.AddLog("Attempting to connect to " + ip + ": " + port); //create our new TelnetClient using the previous IPEndpoint _server = new TelnetClient(ip, port, delay, _serverCancellationToken); //setup our event handlers _server.ConnectionClosed += ConnectionClosedEvent; _server.MessageReceived += MessageReceivedEvent; //set the state to Connecting _serverData.TelnetState = TelnetState.connecting; _server.Connect(); }
public async void ReadTest() { string expected = "/instrumentation/heading-indicator/indicated-heading-deg = (double)\r\n/> "; string expected1 = "/controls/engines/current-engine/throttle = (double)\r\n/> "; TelnetClient client = new TelnetClient(); client.Connect("127.0.0.1", 5402); client.Send("get /instrumentation/heading-indicator/indicated-heading-deg \r\n"); string result = await client.Read(); client.Send("set /controls/engines/current-engine/throttle 1 \r\n"); string result1 = await client.Read(); int index = result.IndexOf('\''); int end = result.IndexOf('\'', index + 1); result = result.Remove(index, end - index + 1); index = result1.IndexOf('\''); end = result1.IndexOf('\'', index + 1); result1 = result1.Remove(index, end - index + 1); Assert.AreEqual(expected, result); Assert.AreEqual(expected1, result1); }