コード例 #1
0
        private void SendStatusMessage()
        {
            while (!this.sendingStatusThreadCancellationTokenSource.IsCancellationRequested)
            {
                //Connect to CS
                statusSocket = communicationModule.SetupClient();
                communicationModule.Connect(statusSocket);

                //Create StatusMessage
                var statusMessage = new StatusMessage()
                {
                    Id      = this.NodeId,
                    Threads = this.statusOfComputingThreads
                };

                //Send StatusMessage to CS
                var messageString = this.SerializeMessage(statusMessage);
                this.communicationModule.SendData(messageString, statusSocket);

                //Receive any response from CS
                var receivedMessage = communicationModule.ReceiveData(statusSocket);

                //Close connection
                this.communicationModule.CloseSocket(statusSocket);

                if (receivedMessage != String.Empty)
                {
                    Trace.WriteLine("Received data from CS: " + receivedMessage);

                    //Received SolvePartialProblems message from CS
                    if (GetMessageName(receivedMessage) == "SolvePartialProblems")
                    {
                        Trace.WriteLine("SolvePartialProblems message recognized");
                        this.AddPartialProblemToQueue(receivedMessage);
                    }

                    //Received unrecoginized message from CS
                    else
                    {
                        Trace.WriteLine("Received unrecognized message!");
                    }
                }
                else
                {
                    Trace.WriteLine("No received data from CS!");
                }

                //Sleep for the period of time given by CS
                Thread.Sleep(4000);
            }
        }