Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Portee v.{Assembly.GetExecutingAssembly().GetName().Version} by Nick Wilson <*****@*****.**>");
            try
            {
                var unknownArgs = p.Parse(args);
                if (unknownArgs.Count > 0 || (Options & optionflags.SHOWHELP) == optionflags.SHOWHELP)
                {
                    var err = new StringBuilder();
                    foreach (var arg in unknownArgs)
                    {
                        _ = err.AppendLine($"Invalid argument: {arg}");
                    }
                    ShowHelp(err.ToString().Trim());
                    Environment.Exit(1);
                }
            }
            catch (OptionException e)
            {
                ShowHelp($"Error: {e.Message}");
                Environment.Exit(1);
            }

            if (Options.HasFlag(optionflags.PROMPT))
            {
                Console.Write("Remote Host: ");
                Remotehost = Console.ReadLine();
                Console.Write("Remote Port: ");
                while (!int.TryParse(Console.ReadLine(), out Localport) || Localport < 1 || Localport > 65535)
                {
                    Console.WriteLine("Invalid Port");
                }
            }

            //Sanity check options
            if (Options.HasFlag(optionflags.READONLY) && Options.HasFlag(optionflags.WRITEONLY))
            {
                ShowHelp("Error: dividing by 0 are we? ReadOnly and WriteOnly options are mutually exclusive");
            }
            if (String.IsNullOrEmpty(Remotehost) && (Remoteport < 1 || Remoteport > 65535))
            {
                ShowHelp("Error: Remote host/port missing or invalid");
                Environment.Exit(1);
            }
            if (Localport < 1 || Localport > 65535)
            {
                ShowHelp("Error: Localport is invalid");
                Environment.Exit(1);
            }
            if (BufferSize < 1 || BufferSize > 1048576)
            {
                ShowHelp("Error: BufferSize is out of range (1-1048576 bytes)");
                Environment.Exit(1);
            }

            //Launch the server
            Server = new SocketServer(Localhost, Localport);
            Client = new SocketClient(Remotehost, Remoteport);
            Server.ReceivedDataHandler += ServerReceivedDataHandler;
            Client.ReceivedDataHandler += ClientReceivedDataHandler;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Portee v.{0} by Nick Wilson",
                  Assembly.GetExecutingAssembly().GetName().Version);
            try
            {
                var unknownArgs = p.Parse(args);
                if (unknownArgs.Count > 0 || (Options & optionflags.SHOWHELP) == optionflags.SHOWHELP)
                {
                    var err = new StringBuilder();
                    foreach (var a in unknownArgs)
                        err.AppendLine(String.Format("Invalid argument: {0}", a));
                    ShowHelp(err.ToString().Trim());
                    Environment.Exit(1);
                }
            }
            catch (OptionException e)
            {
                ShowHelp("Error: " + e.Message);
                Environment.Exit(1);
            }

            if (Options.HasFlag(optionflags.PROMPT))
            {
                Console.Write("Remote Host: ");
                Remotehost = Console.ReadLine();
                Console.Write("Remote Port: ");
                Remoteport = Localport = int.Parse(Console.ReadLine());
            }

            //Sanity check options
            if (Options.HasFlag(optionflags.READONLY) && Options.HasFlag(optionflags.WRITEONLY))
            {
                ShowHelp("Error: dividing by 0 are we?");
            }
            if (String.IsNullOrEmpty(Remotehost) && (Remoteport < 1 || Remoteport > 65535))
            {
                ShowHelp("Error: Remote host/port are missing or invalid");
                Environment.Exit(1);
            }
            if (Localport < 1 || Localport > 65535)
            {
                ShowHelp("Error: Localport is invalid");
                Environment.Exit(1);
            }

            //Launch the server
            Server = new SocketServer(Localhost,Localport);
            Client = new SocketClient(Remotehost,Remoteport);
            Server.ReceivedDataHandler += ServerReceivedDataHandler;
            Client.ReceivedDataHandler += ClientReceivedDataHandler;
        }