private void btnSend_Click(object sender, EventArgs e)
        {
            if (clientCalc1 == null || clientCalc2 == null)
            {
                MessageBox.Show("Objects are not initialized");
                return;
            }

            if (clientCalc1.ClientStatus() != csConnStatus.Connected || clientCalc2.ClientStatus() != csConnStatus.Connected)
            {
                MessageBox.Show("Servers are not available.");
                return;
            }

            stime2 = DateTime.Now;

            int width  = picDraw.Width;
            int height = picDraw.Height;

            string st;

            //// Server1 Command
            st = TSocket.sSTX() + "PS" + Convert.ToString(width) + "," + Convert.ToString(height) + TSocket.sETX();
            clientCalc1.ClientSend(st);

            int RangeMin1 = 2;
            int RangeMax1 = 20000000;

            st = TSocket.sSTX() + "NR" + Convert.ToString(RangeMin1) + "," + Convert.ToString(RangeMax1) + TSocket.sETX();
            clientCalc1.ClientSend(st);

            st = TSocket.sSTX() + "RC" + TSocket.sETX();
            clientCalc1.ClientSend(st);

            // Server2 Command
            st = TSocket.sSTX() + "PS" + Convert.ToString(width) + "," + Convert.ToString(height) + TSocket.sETX();
            clientCalc2.ClientSend(st);

            int RangeMin2 = 20000001;
            int RangeMax2 = 30000000;

            st = TSocket.sSTX() + "NR" + Convert.ToString(RangeMin2) + "," + Convert.ToString(RangeMax2) + TSocket.sETX();
            clientCalc2.ClientSend(st);

            st = TSocket.sSTX() + "RC" + TSocket.sETX();
            clientCalc2.ClientSend(st);

            //calculatePrimeNumber(2, 20000000);
            //foreach (int num in NumPNOrg)
            //{
            //    Console.Write("{0}\r\n", num.ToString());
            //}
        }
        private void GetCommandArrived()
        {
            while (true)
            {
                rbuff += tcpServer.GetRcvMsg();
                int idx1 = rbuff.IndexOf(TSocket.sSTX());
                if (idx1 < 0)
                {
                    break;
                }
                int idx2 = rbuff.IndexOf(TSocket.sETX(), idx1);

                if (idx1 >= 0 && idx2 > idx1)
                {
                    string stCom = rbuff.Substring(idx1 + 1, 2);
                    if (stCom == "PS")      // Picture Size
                    {
                        string   stSize = rbuff.Substring(idx1 + 3, idx2 - (idx1 + 3));
                        string[] pic    = stSize.Split(new char[] { ',' });
                        width  = Convert.ToInt32(pic[0]);
                        height = Convert.ToInt32(pic[1]);

                        loopScale  = (30000000 - 2) / width;
                        loopNumber = (30000000 - 2) / loopScale;

                        lblPic.Text  = "Size: " + Convert.ToString(width) + ", " + Convert.ToString(height);
                        lblStep.Text = "Step: " + Convert.ToString(loopScale);
                    }
                    else if (stCom == "NR") // Number Range
                    {
                        string   stRange = rbuff.Substring(idx1 + 3, idx2 - (idx1 + 3));
                        string[] range   = stRange.Split(new char[] { ',' });
                        NumMin = Convert.ToInt32(range[0]);
                        NumMax = Convert.ToInt32(range[1]);

                        lblRange.Text = "Range: " + Convert.ToString(NumMin) + " ~ " + Convert.ToString(NumMax);
                    }
                    else if (stCom == "RC")  // Request Calculate
                    {
                        IsCalc = true;
                    }
                    rbuff = rbuff.Substring(idx2 + 1);
                }
                else
                {
                    break;
                }
            }
        }
        private void tmCalc_Tick(object sender, EventArgs e)
        {
            if (IsCalc)
            {
                IsCalc         = false;
                tmCalc.Enabled = false;

                lblCalc.Text = "IsCalc: Calculating";
                Application.DoEvents();

                string st = TSocket.sSTX() + "CS" + TSocket.sETX();
                tcpServer.ServerSend(st);

                calculatePrimeNumber(NumMin, NumMax);

                lblCalc.Text = "IsCalc: End";
                Application.DoEvents();

                st = TSocket.sSTX() + "CC" + TSocket.sETX();
                tcpServer.ServerSend(st);

                for (int i = 0; i < loopNumber; i++)
                {
                    IsNext = false;
                    if (i * loopScale + 2 < NumMin || i * loopScale + 2 > NumMax)
                    {
                        continue;
                    }
                    else
                    {
                        if (NumMin <= 2)
                        {
                            st = TSocket.sSTX() + "PN" + Convert.ToString(NumPNOrg[i * loopScale]) + TSocket.sETX();
                        }
                        else if (NumMin > 2)
                        {
                            st = TSocket.sSTX() + "PN" + Convert.ToString(NumPNOrg[(i * loopScale) - NumMin]) + TSocket.sETX();
                        }
                        tcpServer.ServerSend(st);
                    }
                }

                st = TSocket.sSTX() + "TC" + TSocket.sETX();
                tcpServer.ServerSend(st);

                tmCalc.Enabled = true;
            }
        }
        private void GetDataArrived2()
        {
            while (true)
            {
                rbuff2 += clientCalc2.GetRcvMsg();
                int idx1 = rbuff2.IndexOf(TSocket.sSTX());
                if (idx1 < 0)
                {
                    break;
                }
                int idx2 = rbuff2.IndexOf(TSocket.sETX(), idx1);

                if (idx1 >= 0 && idx2 > idx1)
                {
                    string stReq = rbuff2.Substring(idx1 + 1, 2);
                    if (stReq == "PO")
                    {
                        IsPO2 = true;
                    }
                    else if (stReq == "RO")
                    {
                        IsRO2 = true;
                    }
                    else if (stReq == "CS")
                    {
                        lblRsp2.Text = "Respond2: Calculating";
                    }
                    else if (stReq == "CC")
                    {
                        lblRsp2.Text = "Respond2: End";
                        NumPNOrg2.Clear();
                    }
                    else if (stReq == "PN")
                    {
                        string stNum = rbuff2.Substring(idx1 + 3, idx2 - (idx1 + 3));
                        NumPNOrg2.Add(Convert.ToInt32(stNum));
                    }
                    else if (stReq == "TC")
                    {
                        IsDraw2 = true;
                    }
                    // Trim Rx Buffer2
                    rbuff2 = rbuff2.Substring(idx2 + 1);
                }
            }
        }