Beispiel #1
0
        public bool TryHandshake(AmqpProtocol client, out AmqpProtocol server)
        {
            if (_client == null)
            {
                _client = new TcpClient();
                _client.Connect(_endpoint, AmqpPort);
                _stream = _client.GetStream();
                _inner  = _stream;
                UpgradeToTls();
            }

            Span <byte> amqp = stackalloc byte[16]; // slack is needed for read (below)

            amqp[0] = (byte)'A';
            amqp[1] = (byte)'M';
            amqp[2] = (byte)'Q';
            amqp[3] = (byte)'P';
            amqp[4] = (byte)client.Security;
            amqp[5] = client.Major;
            amqp[6] = client.Minor;
            amqp[7] = client.Revision;
            _stream.Write(amqp.Slice(0, 8));
            _stream.Flush();

            amqp.Clear();
            int read     = _stream.Read(amqp);
            var response = amqp.Slice(0, read);

            return(TryParseHandshake(response, out server));
        }
Beispiel #2
0
 bool TryParseHandshake(ReadOnlySpan <byte> response, out AmqpProtocol protocol)
 {
     if (response.Length == 8 && response.StartsWith(s_Amqp))
     {
         protocol          = new AmqpProtocol();
         protocol.Security = (AmqpSecurity)response[4];
         protocol.Major    = response[5];
         protocol.Minor    = response[6];
         protocol.Revision = response[7];
         return(true);
     }
     else
     {
         protocol = default;
         return(false);
     }
 }