コード例 #1
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanPublishEventUsingAPrefix()
        {
            using (var client1 = new WampClient("localhost", 16000))
            using (var client2 = new WampClient("localhost", 16000))
            {
                await client1.Connect();
                await client2.Connect();

                var client1Obs = client1.Subscribe("http://localhost/simple/event#myevent").Replay();
                await Task.Delay(200);

                using (client1Obs.Connect())
                {
                    await client2.Prefix("event", "http://localhost/simple/event#");
                    await client2.Publish("event:myevent", "selfpublishing");

                    var obsTask = client1Obs.Take(1).ToTask();
                    var delay = Task.Delay(5000);

                    var t = await Task.WhenAny(obsTask, delay);

                    Assert.That(delay.Id, Is.Not.EqualTo(t.Id), "Timed out!");
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: paulfryer/Wamplash
        private static void Main(string[] args)
        {
            var client = new WampClient();

            client.Welcome    += client_Welcome;
            client.Subscribed += client_Subscribed;
            client.Event      += client_Event;

            client.Connect(new Uri("ws://wamplash.azurewebsites.net/ws"), "defaultRealm").Wait();

            string topic = "io.crossbar.demo.pubsub.082880";

            client.Subscribe(topic).Wait();

            Thread.Sleep(2000);

            var counter = 0;

            while (true)
            {
                counter++;
                Thread.Sleep(10000);

                var json = "[\"" + Thread.CurrentThread.ManagedThreadId + " CONSOLE ! " + counter + "\"]";

                client.Publish(topic, json);
            }

            System.Console.ReadKey();
        }
コード例 #3
0
ファイル: WampServerTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanStopServer()
        {
            using (var wampServer = new WampServer("localhost", 16000))
            {
                wampServer.Start();

                using (var wampClient = new WampClient("localhost", 16000))
                {
                    var delay = Task.Delay(5000);
                    var connect = wampClient.Connect();

                    var t = await Task.WhenAny(delay, connect);

                    Assert.That(t.Id, Is.EqualTo(connect.Id), "Couldn't connect");
                }

                wampServer.Stop();

                using (var wampClient = new WampClient("localhost", 16000))
                {
                    var delay = Task.Delay(5000);
                    var connect = wampClient.Connect();

                    var t = await Task.WhenAny(delay, connect);

                    Assert.That(t.Id, Is.EqualTo(delay.Id), "Shouldn't have been able to connect");
                }
            }

        }
コード例 #4
0
        private async Task <WampClient> AddEndpoint(Uri endpoint)
        {
            var client = new WampClient();
            await client.Connect(endpoint, "SubscriptionSynchronizer");

            clients.Add(client);
            return(client);
        }
コード例 #5
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanPerformRpcUsingAPrefix()
        {
            using (var csharpFacade = new WampClient("localhost", 16000))
            {
                await csharpFacade.Connect();
                await csharpFacade.Prefix("calc", "http://localhost/simple/calc#");
                var call = csharpFacade.Call("calc:add", "5", "6");
                var delay = Task.Delay(5000);
                var r = await Task.WhenAny(call, delay);

                Assert.That(r.Id, Is.Not.EqualTo(delay.Id), "Timed out!");
                Assert.That(call.Result, Is.EqualTo("11"), "Wrong result");
            }
        }
コード例 #6
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanPerformRpc(double calls)
        {
            using (var csharpFacade = new WampClient("localhost", 16000))
            {
                await csharpFacade.Connect();
                var sw = Stopwatch.StartNew();
                var count = 0;
                while (count++ < calls)
                {
                    var res = await csharpFacade.Call("http://localhost/simple/calc#add", "5", "6");
                    if (count % 1000 == 0)
                        Console.WriteLine("Calls per second: {0}", count / sw.Elapsed.TotalSeconds);
                }
                sw.Stop();

                Console.WriteLine("Total Calls per second: {0}", count / sw.Elapsed.TotalSeconds);
            }
        }
コード例 #7
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanPublishAndReceiveComplexObjectsEvents()
        {
            using (var client1 = new WampClient("localhost", 16000))
            using (var client2 = new WampClient("localhost", 16000))
            {
                await client1.Connect();
                await client2.Connect();

                var client1Obs = client1.Subscribe("http://localhost/simple/event#myevent").Replay();
                await Task.Delay(200);

                using (client1Obs.Connect())
                {
                    await client2.Publish("http://localhost/simple/event#myevent", "{ \"age\": 2 }");
                    var obsTask = client1Obs.Take(1).ToTask();
                    var delay = Task.Delay(5000);
                    var t = await Task.WhenAny(obsTask, delay);

                    Assert.That(delay.Id, Is.Not.EqualTo(t.Id), "Timed out");
                    Assert.That(obsTask.Result, Is.EqualTo("{ \"age\": 2 }"));
                }
            }
        }
コード例 #8
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanSubscribeToFromOneClientAndPublishEventFromAnotherClient()
        {
            using (var client1 = new WampClient("localhost", 16000))
            using (var client2 = new WampClient("localhost", 16000))
            {
                await client1.Connect();
                await client2.Connect();

                var client1Obs = client1.Subscribe("http://localhost/simple/event#myevent").Replay();
                await Task.Delay(200);

                using (client1Obs.Connect())
                {
                    await client2.Publish("http://localhost/simple/event#myevent", "selfpublishing");
                    var obsTask = client1Obs.Take(1).ToTask();
                    var delay = Task.Delay(5000);
                    var t = await Task.WhenAny(obsTask, delay);

                    Assert.That(delay.Id, Is.Not.EqualTo(t.Id), "Timed out");
                    Assert.That(obsTask.Result, Is.EqualTo("\"selfpublishing\""));
                }
            }
        }
コード例 #9
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task WhenSubscribedAndThenUnsubscribeNoLongerReceivePublishedMessages_DualTest()
        {
            using (var client1 = new WampClient("localhost", 16000))
            using (var client2 = new WampClient("localhost", 16000))
            {
                await client1.Connect();
                await client2.Connect();

                var client1Obs = client1.Subscribe("http://localhost/simple/event#myevent").Replay();
                await Task.Delay(200);

                using (client1Obs.Connect())
                {
                    await client2.Publish("http://localhost/simple/event#myevent", "selfpublishing");
                    await client2.Publish("http://localhost/simple/event#myevent", "selfpublishing");

                    var obsTask = client1Obs.Take(2).ToTask();
                    var delay = Task.Delay(5000);

                    var t = await Task.WhenAny(obsTask, delay);

                    Assert.That(delay.Id, Is.Not.EqualTo(t.Id), "Timed out!");
                }
            }
        }
コード例 #10
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanSubscribeToAndPublishEvents()
        {
            using (var csharpFacade = new WampClient("localhost", 16000))
            {
                await csharpFacade.Connect();

                var observable = csharpFacade.Subscribe("http://localhost/simple/event#myevent").Replay();
                await Task.Delay(200);

                using (observable.Connect())
                {
                    await csharpFacade.Publish("http://localhost/simple/event#myevent", "selfpublishing");

                    var res = await observable.Take(1);

                    Assert.That(res, Is.EqualTo("\"selfpublishing\""));
                }
            }
        }
コード例 #11
0
ファイル: WampClientTests.cs プロジェクト: ssboisen/FsWamp
        public async Task CanConnectDisconnectAndConnectAgain()
        {
            using (var csharpFacade = new WampClient("localhost", 16000))
            {
                await csharpFacade.Connect();

                var res = await csharpFacade.Call("add", "5", "6");
                Assert.That(res, Is.EqualTo("11"));
                Console.WriteLine("Got result");
                await csharpFacade.Disconnect();
                Console.WriteLine("Disconnected");
                await csharpFacade.Connect();
                Console.WriteLine("Reconnected");
                var res2 = await csharpFacade.Call("add", "5", "6");
                Console.WriteLine("Got result two");
                Assert.That(res2, Is.EqualTo("11"));
            }
        }