public static string Serialize(JPackage message)
 {
     return(JToken.FromObject(message).ToString());
 }
        static void Main(string[] args)
        {
            string data;
            string ack       = string.Empty;
            int    start     = 0;
            int    chunkSize = 20;

            string temp = File.ReadAllText(@"D:\Network\Client\Text.txt");

            Console.WriteLine();
            Console.WriteLine("*********************** Text file ************************");
            Console.WriteLine();
            Console.WriteLine(temp);
            Console.WriteLine();
            Console.Title = "IdleRQ Primary";

            PackageData package;

            PackageData[] ArrayPackage = GetArrayPackage(temp, chunkSize);
            Console.WriteLine("All size of package is {0}", ArrayPackage.Length);
            IPEndPoint ipep   = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
            Socket     server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                server.Connect(ipep);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Unable to connect to server");
                Console.WriteLine(e.ToString());
                return;
            }

            NetworkStream ns = new NetworkStream(server);
            StreamReader  sr = new StreamReader(ns);
            StreamWriter  sw = new StreamWriter(ns);

            ack = sr.ReadLine();
            Console.WriteLine(ack);
            Console.WriteLine("Press the Enter key to start");
            Console.ReadLine();
            //StartTime();
            ns.ReadTimeout = 2000;

            while (start < ArrayPackage.Length - 1)
            {
                //while (timeout) { }
                //Console.WriteLine("Time out repeat frame {0} again", start);
                // while (status) { }

                if (ack.Equals("ACK"))
                {
                    start++;
                    package = ArrayPackage[start];
                    string obj = JPackage.Serialize(JPackage.FromValue(package));
                    //Console.WriteLine(obj);
                    obj = Base64Encode(obj);
                    sw.WriteLine(obj);
                    sw.Flush();
                    //status = true;
                    ack     = string.Empty;
                    timeout = true;
                }
                else
                {
                    package = ArrayPackage[start];
                    string obj = JPackage.Serialize(JPackage.FromValue(package));
                    //Console.WriteLine(obj);
                    obj = Base64Encode(obj);
                    sw.WriteLine(obj);
                    sw.Flush();
                    //status = true;
                    ack     = string.Empty;
                    timeout = true;
                    aTimer.Start();
                }
                try
                {
                    ack = sr.ReadLine();
                    Console.WriteLine("Server response : {0}", ack);
                }
                catch (Exception)
                {
                    Console.WriteLine("Server response : {0}", ack);
                }
            }
            ns.Close();
            sr.Close();
            sw.Close();
            server.Shutdown(SocketShutdown.Both);
            server.Close();
            aTimer.Stop();
        }