示例#1
0
        public void SocketOptionCookies()
        {
            var options = new Socket.Options();

            options.Cookies.Add("foo", "bar");
            Assert.Equal("foo=bar", options.GetCookiesAsString());
            options.Cookies.Add("name2", "value2");
            Assert.Equal("foo=bar; name2=value2", options.GetCookiesAsString());
        }
示例#2
0
        protected Socket.Options CreateOptions()
        {
            var config  = ConfigBase.Load();
            var options = new Socket.Options();

            options.Port     = config.server.port;
            options.Hostname = config.server.hostname;
            //log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);

            return(options);
        }
        protected static Socket.Options CreateOptions()
        {
            var options = new Socket.Options
            {
                Port     = ConnectionConstants.PORT,
                Hostname = ConnectionConstants.HOSTNAME
            };

            //log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);

            return(options);
        }
示例#4
0
        protected Socket.Options CreateOptionsSecure()
        {
            var config  = ConfigBase.Load();
            var options = new Socket.Options();

            options.Port     = config.server.ssl_port;
            options.Hostname = config.server.hostname;
            //log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
            options.Secure = true;
            options.IgnoreServerCertificateValidation = true;
            return(options);
        }
        protected static Socket.Options CreateOptionsSecure()
        {
            var options = new Socket.Options
            {
                Port     = ConnectionConstants.SSL_PORT,
                Hostname = ConnectionConstants.HOSTNAME,
                //log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
                Secure = true,
                IgnoreServerCertificateValidation = true
            };

            return(options);
        }
示例#6
0
        protected Socket.Options CreateOptionsSecure()
        {
            var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());

            var config  = ConfigBase.Load();
            var options = new Socket.Options();

            options.Port     = config.server.ssl_port;
            options.Hostname = config.server.hostname;
            log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
            options.Secure = true;
            options.IgnoreServerCertificateValidation = true;
            return(options);
        }
示例#7
0
        protected Socket.Options CreateOptions()
        {
            var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());


            var config  = ConfigBase.Load();
            var options = new Socket.Options();

            options.Port     = config.server.port;
            options.Hostname = config.server.hostname;
            log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);

            return(options);
        }
示例#8
0
        protected Socket.Options CreateOptionsSecure()
        {
            LogManager.SetupLogManager();
            var log = LogManager.GetLogger(Global.CallerName());

            var config  = ConfigBase.Load();
            var options = new Socket.Options();

            options.Port     = config.server.ssl_port;
            options.Hostname = config.server.hostname;
            log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
            options.Secure = true;
            options.IgnoreServerCertificateValidation = true;
            return(options);
        }
示例#9
0
        protected Socket.Options CreateOptions()
        {
            LogManager.SetupLogManager();
            var log = LogManager.GetLogger(Global.CallerName());


            var config  = ConfigBase.Load();
            var options = new Socket.Options();

            options.Port     = config.server.port;
            options.Hostname = config.server.hostname;
            log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);

            return(options);
        }
示例#10
0
        protected Socket.Options CreateOptions()
        {
            var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());

            //var config = ConfigBase.Load();
            var options = new Socket.Options
            {
                Port     = ConnectionConstants.PORT,
                Hostname = ConnectionConstants.HOSTNAME
            };

            log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);

            return(options);
        }
示例#11
0
        protected Socket.Options CreateOptionsSecure()
        {
            var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());

            //var config = ConfigBase.Load();
            var options = new Socket.Options
            {
                Port     = ConnectionConstants.SSL_PORT,
                Hostname = ConnectionConstants.HOSTNAME,
                Secure   = true,
                IgnoreServerCertificateValidation = true
            };

            log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
            return(options);
        }
示例#12
0
        public void GeneralIntegrationTest()
        {
            ///
            /// setup
            ///
            var address = string.Format("http://{0}/ops/heartbeat", host);

            // heroku health check
            using (var client = new WebClient())
            {
                // client.Headers.Add("Content-Type", "application/json");
                client.DownloadString(address);
            }

            var onOpenCount = 0;

            Socket.OnOpenDelegate onOpenCallback = () => onOpenCount++;

            var onMessageData = new List <string>();

            Socket.OnMessageDelegate onMessageCallback = m => onMessageData.Add(m);

            // connecting is synchronous as implemented above
            var socketFactory = new WebsocketSharpFactory();
            var socketOptions = new Socket.Options
            {
                channelRejoinInterval = TimeSpan.FromMilliseconds(200),
                heartbeatInterval     = TimeSpan.FromMilliseconds(100),
                logger = new BasicLogger()
            };
            var socket = new Socket(socketFactory, socketOptions);

            socket.OnOpen    += onOpenCallback;
            socket.OnMessage += onMessageCallback;

            socket.Connect(string.Format("ws://{0}/phoenix_sharp_test", host), null);
            Assert.IsTrue(socket.state == Socket.State.Open);
            Assert.AreEqual(1, onOpenCount);

            ///
            /// test channel error on join
            ///
            Reply?okReply     = null;
            Reply?errorReply  = null;
            bool  closeCalled = false;

            var errorChannel = socket.MakeChannel("tester:phoenix-sharp");

            errorChannel.On(Message.InBoundEvent.phx_close, _ => closeCalled = true);

            errorChannel.Join()
            .Receive(Reply.Status.Ok, r => okReply       = r)
            .Receive(Reply.Status.Error, r => errorReply = r);

            Assert.That(() => errorReply.HasValue, Is.True.After(networkDelay, 10));
            Assert.IsNull(okReply);
            Assert.AreEqual(Channel.State.Errored, errorChannel.state);
            // call leave explicitly to cleanup and avoid rejoin attempts
            errorChannel.Leave();
            Assert.IsTrue(closeCalled);

            ///
            /// test channel joining and receiving a custom event
            ///
            Reply?joinOkReply    = null;
            Reply?joinErrorReply = null;

            Message afterJoinMessage = null;
            Message closeMessage     = null;
            Message errorMessage     = null;

            var param = new Dictionary <string, object> {
                { "auth", "doesn't matter" },
            };

            var roomChannel = socket.MakeChannel("tester:phoenix-sharp");

            roomChannel.On(Message.InBoundEvent.phx_close, m => closeMessage = m);
            roomChannel.On(Message.InBoundEvent.phx_error, m => errorMessage = m);
            roomChannel.On("after_join", m => afterJoinMessage = m);

            roomChannel.Join(param)
            .Receive(Reply.Status.Ok, r => joinOkReply       = r)
            .Receive(Reply.Status.Error, r => joinErrorReply = r);

            Assert.That(() => joinOkReply.HasValue, Is.True.After(networkDelay, 10));
            Assert.IsNull(joinErrorReply);

            Assert.That(() => afterJoinMessage != null, Is.True.After(networkDelay, 10));
            Assert.AreEqual("Welcome!", afterJoinMessage.payload["message"].Value <string>());

            // 1. heartbeat, 2. error, 3. join, 4. after_join
            Assert.AreEqual(4, onMessageData.Count, "Unexpected message count: " + string.Join("; ", onMessageData));

            ///
            /// test echo reply
            ///
            var payload = new Dictionary <string, object> {
                { "echo", "test" }
            };

            Reply?testOkReply = null;

            roomChannel
            .Push("reply_test", payload)
            .Receive(Reply.Status.Ok, r => testOkReply = r);

            Assert.That(() => testOkReply.HasValue, Is.True.After(networkDelay, 10));
            Assert.IsNotNull(testOkReply.Value.response);
            CollectionAssert.AreEquivalent(testOkReply.Value.response.ToObject <Dictionary <string, object> >(), payload);

            ///
            /// test error reply
            ///
            Reply?testErrorReply = null;

            roomChannel
            .Push("error_test")
            .Receive(Reply.Status.Error, r => testErrorReply = r);

            Assert.That(() => testErrorReply.HasValue, Is.True.After(networkDelay, 10));
            Assert.AreEqual(testErrorReply.Value.status, Reply.Status.Error);

            ///
            /// test timeout reply
            ///
            Reply?testTimeoutReply = null;

            roomChannel
            .Push("timeout_test", null, TimeSpan.FromMilliseconds(50))
            .Receive(Reply.Status.Timeout, r => testTimeoutReply = r);

            Assert.That(() => testTimeoutReply.HasValue, Is.False.After(40));
            Assert.That(() => testTimeoutReply.HasValue, Is.True.After(60));

            ///
            /// test channel error/rejoin
            ///
            Assert.IsNull(errorMessage);
            // we track rejoining through the same join push callback we setup
            joinOkReply = null;

            socket.Disconnect();
            socket.Connect(string.Format("ws://{0}/phoenix_sharp_test", host), null);

            Assert.That(() => errorMessage != null, Is.True.After(networkDelay, 10));
            Assert.That(() => joinOkReply != null, Is.True.After(networkDelay, 10));
            Assert.That(() => roomChannel.CanPush, Is.True.After(networkDelay, 10));

            ///
            /// test channel replace
            ///
            joinOkReply    = null;
            joinErrorReply = null;
            errorMessage   = null;
            Assert.IsNull(closeMessage);
            Message newCloseMessage = null;

            var newRoomChannel = socket.MakeChannel("tester:phoenix-sharp");

            newRoomChannel.On(Message.InBoundEvent.phx_close, m => newCloseMessage = m);

            newRoomChannel.Join(param)
            .Receive(Reply.Status.Ok, r => joinOkReply       = r)
            .Receive(Reply.Status.Error, r => joinErrorReply = r);

            Assert.That(() => joinOkReply.HasValue, Is.True.After(networkDelay, 10));
            Assert.IsNull(joinErrorReply);
            Assert.IsNotNull(errorMessage);
            Assert.IsNotNull(closeMessage);

            ///
            /// test channel leave
            /// also, it should discard any additional messages
            ///
            Assert.IsNull(newCloseMessage);
            Message pushMessage = null;

            newRoomChannel.On("push_test", m => pushMessage = m);
            newRoomChannel.Push("push_test", payload);

            Assert.IsNull(pushMessage);
            newRoomChannel.Leave();

            Assert.That(() => newCloseMessage != null, Is.True.After(networkDelay, 10));
            Assert.IsNull(pushMessage); // ignored
        }