Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        public override Server creack(String ip, int port, String username, String password, int timeOut)
        {
            TelnetClient tc = null;

            Server server = new Server();

            try
            {
                tc = new TelnetClient(ip, port);
                String s      = tc.Login(username, password, timeOut * 1000);
                String prompt = s.TrimEnd();
                prompt        = s.Substring(prompt.Length - 1, 1);
                server.banner = prompt;
                if (prompt != "$" && prompt != ">")
                {
                    return(server);
                }

                if (tc.IsConnected)
                {
                    server.isSuccess = true;;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (tc != null)
                {
                    tc.Dispose();
                }
            }
            return(server);
        }