/// <summary>Start asynchronously reading from the TCP client</summary> public void Start(Main parent) { var connect = new ProgressForm("Connecting...", "Connecting to " + m_conn.PipeAddr, null, ProgressBarStyle.Marquee, (s, a, cb) => { cb(new ProgressForm.UserState { ProgressBarVisible = false, Icon = parent.Icon }); while (!m_pipe.IsConnected && !s.CancelPending) { try { m_pipe.Connect(100); } catch (TimeoutException) {} } if (!s.CancelPending) { m_pipe.ReadMode = PipeTransmissionMode.Byte; var src = new StreamSource(m_pipe); src.BeginRead(m_buf, 0, m_buf.Length, DataRecv, new AsyncData(src, m_buf)); } }); using (connect) if (connect.ShowDialog(parent) != DialogResult.OK) { throw new OperationCanceledException("Connecting cancelled"); } }
public void Start() { m_process.Start(); Log.Write(ELogLevel.Info, $"Process {m_process.StartInfo.FileName} started"); // Attach to the window console so we can forward received data to it if (m_launch.ShowWindow) { Win32.AttachConsole(m_process.Id); } // Capture stdout if (m_launch.CaptureStdout) { var stdout = new StreamSource(m_process.StandardOutput.BaseStream); stdout.BeginRead(m_outbuf, 0, m_outbuf.Length, DataRecv, new AsyncData(stdout, m_outbuf)); } // Capture stderr if (m_launch.CaptureStderr) { var stderr = new StreamSource(m_process.StandardError.BaseStream); stderr.BeginRead(m_errbuf, 0, m_errbuf.Length, DataRecv, new AsyncData(stderr, m_errbuf)); } }
/// <summary>Start asynchronously reading from the TCP client</summary> public void Start() { m_port.Open(); m_port.BaseStream.ReadTimeout = Constants.FilePollingRate; var src = new StreamSource(m_port.BaseStream); src.BeginRead(m_buf, 0, m_buf.Length, DataRecv, new AsyncData(src, m_buf)); }
/// <summary>Start a TCP client that connects to a server that is producing log data</summary> private void StartClient(Main parent) { var connect = new ProgressForm("Connecting...", $"Connecting to remote host: {m_conn.Hostname}:{m_conn.Port}", parent.Icon, ProgressBarStyle.Marquee, (s, a, cb) => { cb(new ProgressForm.UserState { ProgressBarVisible = false, Icon = parent.Icon }); m_client = new TcpClient(); var proxy = m_conn.ProxyType == Proxy.EType.None ? null : Proxy.Create(m_conn.ProxyType, m_conn.ProxyHostname, m_conn.ProxyPort, m_conn.ProxyUserName, m_conn.ProxyPassword); // Connect async var ar = proxy != null ? proxy.BeginConnect(m_conn.Hostname, m_conn.Port) : m_client.BeginConnect(m_conn.Hostname, m_conn.Port, null, null); for (; !s.CancelPending && !ar.AsyncWaitHandle.WaitOne(500);) { } if (!s.CancelPending) { if (proxy != null) { m_client = proxy.EndConnect(ar); } else { m_client.EndConnect(ar); } var src = new StreamSource(m_client.GetStream()); src.BeginRead(m_buf, 0, m_buf.Length, DataRecv, new AsyncData(src, m_buf)); } }); using (connect) if (connect.ShowDialog(parent) != DialogResult.OK) { throw new OperationCanceledException("Connecting cancelled"); } }
/// <summary>Start a TCP server that listens for incoming connections from clients</summary> private void StartListener(Main parent) { var connect = new ProgressForm("Listening...", $"Waiting for connections on port: {m_conn.Port}", parent.Icon, ProgressBarStyle.Marquee, (s, a, cb) => { cb(new ProgressForm.UserState { ProgressBarVisible = false, Icon = parent.Icon }); var listener = new TcpListener(IPAddress.Any, m_conn.Port); listener.Start(); try { // Listen async var ar = listener.BeginAcceptTcpClient(r => {}, null); for (; !s.CancelPending && !ar.AsyncWaitHandle.WaitOne(500);) { } if (!s.CancelPending) { m_client = listener.EndAcceptTcpClient(ar); listener.Stop(); var src = new StreamSource(m_client.GetStream()); src.BeginRead(m_buf, 0, m_buf.Length, DataRecv, new AsyncData(src, m_buf)); } } finally { listener.Stop(); } }); using (connect) if (connect.ShowDialog(parent) != DialogResult.OK) { throw new OperationCanceledException("Connecting cancelled"); } }