void Connected(object sender, TcpServer.ConnectedEventArgs e)
		{
			try
			{
				System.Security.Cryptography.MD5 MD5 = System.Security.Cryptography.MD5.Create();

				using (ReaderWriter io = new ReaderWriter(e.Stream))
				{
					while (true)
					{
						byte[] bytes = io.Read();
						if (bytes.Length == 0)
							break;
						io.Write(MD5.ComputeHash(bytes));
					}
				}
			}
			finally { e.Close(); }
		}
Exemple #2
0
        void Connected(object sender, TcpServer.ConnectedEventArgs e)
        {
            try
            {
                System.Security.Cryptography.MD5 MD5 = System.Security.Cryptography.MD5.Create();

                using (ReaderWriter io = new ReaderWriter(e.Stream))
                {
                    while (true)
                    {
                        byte[] bytes = io.Read();
                        if (bytes.Length == 0)
                        {
                            break;
                        }
                        io.Write(MD5.ComputeHash(bytes));
                    }
                }
            }
            finally { e.Close(); }
        }
Exemple #3
0
        //Client TEST
        public static void Test(string host, int port, int repeate, params int[] sizes)
        {
            System.Security.Cryptography.MD5 MD5 = System.Security.Cryptography.MD5.Create();

            int       sent  = 0;
            Random    rand  = new Random();
            Stopwatch watch = new Stopwatch();

            watch.Start();

            using (TcpClient client = new TcpClient(host, port))
            {
                client.Connect();
                using (ReaderWriter io = new ReaderWriter(client.Stream))
                {
                    for (int count = 0; count < repeate; count++)
                    {
                        int    size  = sizes[count % sizes.Length];
                        byte[] bytes = new byte[size];

                        rand.NextBytes(bytes);
                        byte[] md5 = MD5.ComputeHash(bytes);

                        io.Write(bytes);
                        byte[] resultMd5 = io.Read();

                        Assert.AreEqual(Convert.ToBase64String(md5), Convert.ToBase64String(resultMd5));
                        sent++;
                    }

                    io.Write(new byte[0] {
                    });
                }
            }

            watch.Stop();
            Trace.TraceInformation("Sent {0} requests to port {1} in {2}", sent, port, watch.Elapsed);
        }
		//Client TEST
		public static void Test(string host, int port, int repeate, params int[] sizes)
		{
			System.Security.Cryptography.MD5 MD5 = System.Security.Cryptography.MD5.Create();

			int sent = 0;
			Random rand = new Random();
			Stopwatch watch = new Stopwatch();
			watch.Start();

			using (TcpClient client = new TcpClient(host, port))
			{
				client.Connect();
				using (ReaderWriter io = new ReaderWriter(client.Stream))
				{
					for (int count = 0; count < repeate; count++)
					{
						int size = sizes[count % sizes.Length];
						byte[] bytes = new byte[size];

						rand.NextBytes(bytes);
						byte[] md5 = MD5.ComputeHash(bytes);
						
						io.Write(bytes);
						byte[] resultMd5 = io.Read();

						Assert.AreEqual(Convert.ToBase64String(md5), Convert.ToBase64String(resultMd5));
						sent++;
					}

					io.Write(new byte[0] {});
				}
			}

			watch.Stop();
			Trace.TraceInformation("Sent {0} requests to port {1} in {2}", sent, port, watch.Elapsed);
		}