ReadByte() public method

public ReadByte ( ) : int
return int
Esempio n. 1
0
        static string ReadMessage(SslStream sslStream)
        {
            // Read the  message sent by the client.
            // The client signals the end of the message using the
            // "" marker.
            StringBuilder messageData = new StringBuilder();
            int bytes = -1;
            do
            {
                // Read the client's test message.
                bytes = sslStream.ReadByte();

                // Use Decoder class to convert from bytes to UTF8
                // in case a character spans two buffers.
                Decoder decoder = Encoding.UTF8.GetDecoder();
                char znak = (char)bytes;
                messageData.Append(znak);
                // Check for EOF or an empty message.
                if (messageData.ToString().IndexOf("") != -1)
                {
                    break;
                }
            } while (bytes != 0);

            return messageData.ToString();
        }
Esempio n. 2
0
        public void ssl_stream_with_client_certificates()
        {
            var net = new TestNetwork();

            var server = new Thread(
                () =>
                {
                    var ssl = new SslStream(net.Server, false, Validate);

                    ssl.AuthenticateAsServer(ServerCert, true, SslProtocols.Tls, false);

                     SslInfo("Server", ssl);

                    Assert.That(ssl.ReadByte() == 1);

                    ssl.WriteByte(2);
                });

            server.Start();

            var client = new Thread(
                () =>
                {
                    var ssl = new SslStream(net.Client, false, Validate, SelectCert);

                    ssl.AuthenticateAsClient("server.x", new X509CertificateCollection(new[] { ClientCert }), SslProtocols.Tls, false);

                    SslInfo("Client", ssl);

                    ssl.WriteByte(1);

                    Assert.That(ssl.ReadByte() == 2);
                });

            client.Start();

            server.Join();
            client.Join();
        }
 private string streamReadLine(SslStream inputStream)
 {
     int next_char;
     string data = "";
     while (true) {
         next_char = inputStream.ReadByte();
         if (next_char == '\n') { break; }
         if (next_char == '\r') { continue; }
         if (next_char == -1) { Thread.Sleep(1); continue; };
         data += Convert.ToChar(next_char);
     }
     return data;
 }
 /**
  * Internal method to read HTTP response header lines. Used by getHeader()
  */
 private string readline(SslStream s)
 {
     StringBuilder sb = new StringBuilder();
     Int32 i = 0;
     char c = (char)0;
     try
     {
         do
         {
             i = s.ReadByte();
             if (i == -1)
                 break;
             c = Convert.ToChar(i);
             if (c == '\n')
                 break;
             if (c != '\r')
                 sb.Append(c);
         }
         while (true);
     }
     catch (Exception e)
     {
         EventLog logger = new EventLog("Application");
         logger.Source = LOGSOURCE;
         StringBuilder sbe = new StringBuilder("Unexpected error ");
         sbe.Append(e.ToString());
         sbe.Append(" reading response header.");
         logger.WriteEntry(sbe.ToString(), EventLogEntryType.Error);
     }
     return sb.ToString();
 }