public void Eio4Connected()
        {
            var msg = new ConnectedMessage
            {
                Eio = 4
            };
            string text = msg.Write();

            Assert.AreEqual("40", text);
        }
Exemplo n.º 2
0
        private void OnConnected()
        {
            ConnectedMessage connectedMessage = new ConnectedMessage
            {
                Connection = this,
                Host       = host,
                Port       = port,
            };

            messageSink.Send(connectedMessage);
        }
        public void Eio4NamespaceConnected()
        {
            var msg = new ConnectedMessage
            {
                Eio       = 4,
                Namespace = "/microsoft"
            };
            string text = msg.Write();

            Assert.AreEqual("40/microsoft,", text);
        }
        public void Eio3WsWithoutQueryConnected()
        {
            var msg = new ConnectedMessage
            {
                Eio       = 3,
                Protocol  = TransportProtocol.WebSocket,
                Namespace = "/admin"
            };
            string text = msg.Write();

            Assert.AreEqual("40/admin,", text);
        }
Exemplo n.º 5
0
    internal void Deserialize(byte[] data, ConnectedMessage expected)
    {
        var message = ConnectedMessageSerializer.Default.Deserialize(data);

        message.Command.Should().Be(expected.Command);
        message.Opcode.Should().Be(expected.Opcode);
        message.MessageId.Should().Be(expected.MessageId);
        message.ResponseId.Should().Be(expected.ResponseId);
        message.ProtocolVersion.Should().Be(expected.ProtocolVersion);
        message.SessionId.Should().Be(expected.SessionId);
        message.Timestamp.Should().Be(expected.Timestamp);
    }
Exemplo n.º 6
0
        public Sender()
        {
            m_NetworkStream = null;
            m_Reader = new NetworkReader();
            m_Writer = new NetworkWriter();

            // Messages
            m_Handshake = new HandshakeMessage();
            m_Connected = new ConnectedMessage();
            m_Command = new CommandMessage();

            m_State = ConnectionState.Disconnected;
        }
Exemplo n.º 7
0
        public Responder()
        {
            m_NetworkStream = null;
            m_Reader = new NetworkReader();
            m_Writer = new NetworkWriter();

            // Messages
            m_Handshake = new HandshakeMessage();
            m_Command = new CommandMessage();
            m_Connected = new ConnectedMessage();
            m_Disconnected = new DisconnectedMessage();
            m_SendError = new SendErrorMessage();
        }
Exemplo n.º 8
0
        protected virtual async Task OpenAsync(OpenedMessage msg)
        {
            OpenedMessage = msg;
            var connectMsg = new ConnectedMessage
            {
                Namespace = Namespace,
                Eio       = EIO,
                Query     = Options.Query
            };

            for (int i = 1; i <= 3; i++)
            {
                try
                {
                    await SendAsync(connectMsg.Write(), CancellationToken.None).ConfigureAwait(false);

                    break;
                }
                catch (Exception e)
                {
                    if (i == 3)
                    {
                        Trace.TraceError(e.ToString());
                    }
                    else
                    {
                        await Task.Delay(TimeSpan.FromMilliseconds(Math.Pow(2, i) * 100));
                    }
                }
            }

            /*
             * try
             * {
             *  await Policy
             *     .Handle<Exception>()
             *     .WaitAndRetryAsync(3, attempt => TimeSpan.FromMilliseconds(Math.Pow(2, attempt) * 100))
             *     .ExecuteAsync(async () =>
             *     {
             *         await SendAsync(connectMsg.Write(), CancellationToken.None).ConfigureAwait(false);
             *     }).ConfigureAwait(false);
             *
             * }
             * catch (Exception e)
             * {
             *  Trace.TraceError(e.ToString());
             *  OnTransportClosed();
             * }
             */
        }
Exemplo n.º 9
0
        private void Connect(string host, Authentication auth)
        {
            var message = auth == null
                              ? new ConnectMessage(host)
                              : new ConnectMessage(host, auth.Username, auth.Password);

            message.WriteTo(_stream);

            var answerFrame = Frame.ReadFrom(_stream);

            ErrorMessage.ThrowIfIsError(answerFrame);

            var connected = new ConnectedMessage(answerFrame);

            _protocolVersion = connected.ProtocolVersion;
        }
        public void Eio3WsWith1ParamConnected()
        {
            var msg = new ConnectedMessage
            {
                Eio       = 3,
                Protocol  = TransportProtocol.WebSocket,
                Namespace = "/apple",
                Query     = new Dictionary <string, string>
                {
                    { "a", "123" }
                }
            };
            string text = msg.Write();

            Assert.AreEqual("40/apple?a=123,", text);
        }
Exemplo n.º 11
0
        public AbstractMessage Parse(string input)
        {
            Regex regex = new Regex(pattern);

            if (regex.IsMatch(input))
            {
                ConnectedMessage abstractMessage = new ConnectedMessage();
                var match = regex.Match(input);
                abstractMessage.UserName    = match.Groups["userName"].Value;
                abstractMessage.UserID      = match.Groups["userId"].Value;
                abstractMessage.UserSteamID = match.Groups["userSteamId"].Value;
                abstractMessage.Address     = match.Groups["address"].Value;

                return(abstractMessage);
            }
            return(null);
        }
        public void Eio3WsWith2ParamConnected()
        {
            var msg = new ConnectedMessage
            {
                Eio       = 3,
                Protocol  = TransportProtocol.WebSocket,
                Namespace = "/razer",
                Query     = new Dictionary <string, string>
                {
                    { "a", "123" },
                    { "token", "qwer" }
                }
            };
            string text = msg.Write();

            Assert.AreEqual("40/razer?a=123&token=qwer,", text);
        }
Exemplo n.º 13
0
        protected virtual async Task OpenAsync(OpenedMessage msg)
        {
            OpenedMessage = msg;
            if (Options.EIO == 3 && string.IsNullOrEmpty(Namespace))
            {
                return;
            }
            var connectMsg = new ConnectedMessage
            {
                Namespace = Namespace,
                Eio       = Options.EIO,
                Query     = Options.Query,
            };

            if (Options.EIO == 4)
            {
                if (Options.Auth != null)
                {
                    connectMsg.AuthJsonStr = JsonSerializer.Serialize(new[] { Options.Auth }).Json.TrimStart('[').TrimEnd(']');
                }
            }

            for (int i = 1; i <= 3; i++)
            {
                try
                {
                    await SendAsync(connectMsg, CancellationToken.None).ConfigureAwait(false);

                    break;
                }
                catch (Exception e)
                {
                    if (i == 3)
                    {
                        OnError(e);
                    }
                    else
                    {
                        await Task.Delay(TimeSpan.FromMilliseconds(Math.Pow(2, i) * 100));
                    }
                }
            }
        }
Exemplo n.º 14
0
 private void OnConnected()
 {            
     ConnectedMessage connectedMessage = new ConnectedMessage
     {
         Connection = this,
         Host = host,
         Port = port,
     };
     messageSink.Send(connectedMessage);
 }
Exemplo n.º 15
0
 internal void Serialize(byte[] expected, ConnectedMessage message)
 {
     ConnectedMessageSerializer.Default.Serialize(message).Should().Equal(expected);
 }