Пример #1
0
        static void Main(string[] args)
        {
            name = Console.ReadLine();
            try
            {
                Int32     port    = 13000;
                TcpClient _server = new TcpClient("localhost", port);
                server = new ServerCommunication(_server);
                //server.UseAudioDriver(new AudioDriver());
                Task.Run(() => RenderScreen());

                while (true)
                {
                    Console.ReadKey();
                }
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("ArgumentNullException: {0}", e);
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }
        }
        /// <summary>
        /// This is the default constructor of the class
        /// </summary>
        public frmClient()
        {
            //
            // Required for Windows Form Designer support
            //
            // Auto generated function by the IDE
            InitializeComponent();

            // Puts the Computer.ico as the form icon
            this.Icon = new System.Drawing.Icon(Application.StartupPath + "\\Computer.ico");

            // Creates a new instance of XMLParser class
            xmlParser = new WorkingWithXML.XMLParser();

            // Creates a new instance of XMLSTRUCT structure
            xmlStruct = new WorkingWithXML.XMLSTRUCT();

            // Creates a new instance for ServerCommunication class
            xmlServerComm = new WorkingWithXML.ServerCommunication();

            // Assigns the global value for USERLISTXML
            xmlParser.USERLISTXML = Application.StartupPath + "\\userlist.xml";

            // Assigns the global value for SERVERSEARCHXML
            xmlParser.SERVERSEARCHRESULTXML = Application.StartupPath + "\\search.xml";
            try
            {
                // Fills the List view with the values
                // these values are the response from the server
                if (0 == PopulateList())
                {
                    // Displays a message if no computer is connected to the network
                    throw new Exception("No computer is connected to the network. The list will be empty");
                }
            }

            // Hanldes every exceptions that is thrown
            catch (Exception err) { MessageBox.Show(err.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
        }
Пример #3
0
        private static void runClient()
        {
            Logger.Info("Client");
            Console.WriteLine("Server IP:");
            var ip = Console.ReadLine();

            if (!IPAddress.TryParse(ip, out _))
            {
                throw new Exception("Unable to parse IP!");
            }

            Console.WriteLine("Server Port:");
            var port = int.Parse(Console.ReadLine() ?? throw new Exception("Unable to parse server port!"));

            var serverCommunication = new ServerCommunication(ip, port);
            var taskRunner          = new TaskRunner.TaskRunner(serverCommunication, _assemblyLocation);

            taskRunner.BeginReceivingTasks();


            Logger.Info("Exitting...");
            Console.ReadLine();
        }