Esempio n. 1
0
        public void sendMessage(int hostname, int port, addressBook myContacts)
        {
            try
            {   
                Utilities myUtilities = new Utilities();
                byte[] ba = enterMessage(hostname, myContacts);
                Console.WriteLine("Connecting.....");
                TcpClient tcpclnt = new TcpClient(myContacts.returnHostname(hostname), port);
                Stream stm = tcpclnt.GetStream();
                            
                Console.WriteLine("Transmitting.....");
                //encrypt the message
                byte[] cipherText = myUtilities.encrypt(ba, 20, "password");
                //Console.WriteLine("Finished encryption");
                //write cipherText to current stream
                stm.Write(cipherText, 0, cipherText.Length);
                Console.WriteLine("Messege send succesful");

                tcpclnt.Close();
            }

            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.StackTrace);
            }
        }