Exemplo n.º 1
0
        /// <summary>
        /// Main start of RenderClient
        /// The only method needed to be called from outside
        /// </summary>
        public static void Start()
        {
            while (true)    // this loop is exited by Environment.Exit ( 1 ) in EndOfRenderClientWork ()
            {
                try
                {
                    //displays external and internal IP addresses for easier connection establishment
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Your external IP address is: " + NetworkSupport.GetExternalIPAddress());
                    Console.WriteLine("Your local IP address is: " + NetworkSupport.GetLocalIPAddress() + '\n');

                    Console.WriteLine(@"Waiting for remote server to connect to this client...");

                    ConnectToServer();

                    Console.WriteLine(@"Client succesfully connected.");
                }
                catch (SocketException)       // thrown in case of multiple clients being launched on the same computer
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\nYou can not start more than one client on the same computer.");

                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("\nPress any key to exit this RenderClient...\n");

                    Console.ReadKey();
                    return;
                }

                finished = false;

                ExchangeNecessaryInfo();

                Thread receiver = new Thread(ReceiveAssignments);
                receiver.Name     = "AssignmentReceiver";
                receiver.Priority = ThreadPriority.BelowNormal;
                receiver.Start();

                ClientMaster.singleton.StartThreads(threadCount);

                EndOfRenderClientWork();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Thread in infinite loop accepting new assignments
        /// Loop is ended by receiving Ending Assignment
        /// </summary>
        private static void ReceiveAssignments()
        {
            while (true)
            {
                try
                {
                    if (stream.DataAvailable)
                    {
                        Assignment newAssignment = NetworkSupport.ReceiveObject <Assignment>(stream);

                        if (newAssignment.type == Assignment.AssignmentType.Ending) // Ending assignment signals end of rendering
                        {
                            finished = true;                                        // signal for threads in Consume method

                            lock (consoleLock)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\nRendering on server finished or no more assignments are expected to be received.\n");
                            }

                            return;
                        }

                        lock (consoleLock)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine(@"Data for assignment [{0}, {1}, {2}, {3}] received and deserialized.", newAssignment.x1, newAssignment.y1, newAssignment.x2, newAssignment.y2);
                        }

                        ClientMaster.singleton.availableAssignments.Enqueue(newAssignment); // adds new assignment to the queue; it is later taken from there by thread in Consume method
                    }
                }
                catch (ObjectDisposedException)
                {
                    ConnectionLost();
                }
            }
        }
 // This makes a local instrument
 public NetworkRedirector(NetworkSupport <T> controller)
     : this(controller, PhotonNetwork.player.ID)
 {
 }