// (c) 2006 Richard Grimes // www.grimes.demon.co.uk using System; using System.Security.Cryptography; using System.Net.Sockets; using System.Net; using System.Text; class Bob { static void Main() { CspParameters csp = new CspParameters(1, null, "Bob"); RSACryptoServiceProvider rsaBobPrivKey = new RSACryptoServiceProvider(csp); TcpListener listener = new TcpListener(IPAddress.Loopback, 5000); listener.Start(); while (true) { Console.WriteLine("Waiting for connection..."); TcpClient client = listener.AcceptTcpClient(); NetworkStream stm = client.GetStream(); byte[] buf = new byte[client.ReceiveBufferSize]; int read = stm.Read(buf, 0, buf.Length); string command = Encoding.ASCII.GetString(buf, 0, read); if (command.ToLower() != "key") { client.Close(); break; } Console.WriteLine("command: {0}", command); byte[] ack = Encoding.ASCII.GetBytes("ACK"); stm.Write(ack, 0, ack.Length); read = stm.Read(buf, 0, buf.Length); Console.WriteLine(BitConverter.ToString(buf, 0, read)); client.Close(); } Console.WriteLine("Stopping..."); listener.Stop(); } }