Esempio n. 1
0
        public bool Start(string host, int port)
        {
            try
            {
                _ClientSocket.Connect(host, port);
                Console.WriteLine("Client connected.");
                if (!_StreamSSL.AuthenticateAsClient(_ClientSocket, SslProtocols.Tls12))
                {
                    return(false);
                }

                new Thread(ThreadReceive).Start();

                byte[] messsage = Encoding.UTF8.GetBytes("Hello from the client.<EOF>\n");
                // Send hello message to the server.
                _StreamSSL.Encrypt(messsage, 0, messsage.Length);
                do
                {
                    string msg = Console.ReadLine() + "\n";
                    // Send hello message to the server.
                    //messsage = Encoding.UTF8.GetBytes(msg);
                    _StreamSSL.Encrypt(msg, Encoding.UTF8);
                    if (msg == "exit")
                    {
                        break;
                    }
                } while (true);
                // Close the client connection.
                _ClientSocket.Close();
                Console.WriteLine("Client closed.");
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
                Close();
            }
            return(false);
        }
Esempio n. 2
0
 public void Start(Socket ClientSocket)
 {
     if (ClientSocket == null || !ClientSocket.Connected)
     {
         return;
     }
     _ChannelIsClosed = false;
     _ChannelSocket   = ClientSocket;
     SetKeepAlive(_Settings.HeartBeatPeriod);
     if (_UseSSL)
     {
         if (_AsSslClient)
         {
             _StreamSSL.AuthenticateAsClient(_ChannelSocket, _SslProtocol);
         }
         else
         {
             _StreamSSL.AuthenticateAsServer(_ChannelSocket, _Certificate);
         }
     }
     StartReceive();
 }