Esempio n. 1
0
        public void Start()
        {
            if (IsRunning)
            {
                throw new Exception("Kcptun running");
            }
            if (_server == null)
            {
                throw new Exception("No Server");
            }

            try
            {
                Configuration config   = controller.ConfigController.GetCurrentConfiguration();
                string        filename = GetKCPTunPath();
                Console.WriteLine($"kcptun client: {filename}");
                MyProcess p = new MyProcess(_server);
                p.StartInfo.FileName               = filename;
                p.StartInfo.Arguments              = BuildArguments(config.snmp, _server, localaddr, remoteaddr);
                p.StartInfo.WorkingDirectory       = Utils.GetTempPath();
                p.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.RedirectStandardError  = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.ErrorDataReceived  += OnProcessErrorDataReceived;
                p.OutputDataReceived += OnProcessOutputDataReceived;
                p.Exited             += OnProcessExited;
                p.EnableRaisingEvents = true;
                p.Start();
                _process = p;
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();

                Console.WriteLine("kcptun client started - " + p.server.FriendlyName());

                if (Started != null)
                {
                    Started.Invoke(this, new EventArgs());
                }
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
            }
        }