void Receive()
        {
            NetworkStream networkStream = new NetworkStream(this.ClientSocket);

            while (true)
            {
                Postman postMan = Postman.GetPackage(networkStream);
                Console.WriteLine(postMan);
                switch (postMan.Type)
                {
                case Postman.PostmanType.SEND_KEY:
                    this.ServerMysterio.PubKey = Mysterio.ConvertBytesToKey(postMan.Payload);
                    break;

                case Postman.PostmanType.SEND_MESSAGE:
                    string plainText = Mysterio.Decrypt(this.ClientMysterio.PriKey, postMan.Payload);
                    Console.WriteLine(plainText);
                    break;
                }
                if (postMan.Type == Postman.PostmanType.DISCONNECT)
                {
                    break;
                }
            }
            networkStream.Close();
        }
Example #2
0
        private void Receive()
        {
            try
            {
                NetworkStream netStream = new NetworkStream(this.ReceiveSocket);
                while (true)
                {
                    Postman postman = Postman.GetPackage(netStream);
                    RenderForm();
                    switch (postman.Type)
                    {
                    case Postman.PostmanType.SEND_KEY:
                        this.OtherMysterio.PubKey = Mysterio.ConvertBytesToKey(postman.Payload);
                        break;

                    case Postman.PostmanType.SEND_MESSAGE:
                        string plainText = Mysterio.Decrypt(this.MyMysterio.PriKey, postman.Payload);
                        ThreadHelper.AppendMessages(this, txtMessages, DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt\t") + plainText, false);
                        break;
                    }
                    AddEvent(postman.Type.ToString(), Encoding.Unicode.GetString(postman.Payload));
                }
            }catch (Exception e)
            {
                //MessageBox.Show(e.Message);
                Stop();
            }
        }