Beispiel #1
0
        private static void HostCode()
        {
            DefaultWampAuthenticationHost host =
                new DefaultWampAuthenticationHost("ws://127.0.0.1:8080/ws",
                                                  new WampCraUserDbAuthenticationFactory(new MyAuthenticationProvider(),
                                                                                         new MyUserDb()));

            IWampHostedRealm realm = host.RealmContainer.GetRealmByName("realm1");

            string[] topics = new[]
            {
                "com.example.topic1",
                "com.foobar.topic1",
                "com.foobar.topic2"
            };

            foreach (string topic in topics)
            {
                string currentTopic = topic;

                realm.Services.GetSubject <string>(topic).Subscribe
                    (x => Console.WriteLine("event received on {0}: {1}", currentTopic, x));
            }

            realm.Services.RegisterCallee(new Add2Service()).Wait();

            host.Open();
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            int    serverPort    = PortUtils.FindAvailablePortIncrementally(18889);
            string serverAddress = $"ws://127.0.0.1:{serverPort}/ws";

            //WampHost host = new DefaultWampHost(serverAddress);
            DefaultWampAuthenticationHost host = new DefaultWampAuthenticationHost(serverAddress, new VergicWampAuthenticatorFactory());

            IWampHostedRealm realm = host.RealmContainer.GetRealmByName("vivego");

            realm.SessionCreated += Realm_SessionCreated;
            realm.SessionClosed  += Realm_SessionClosed;

            //EnableDistributedBackplane(realm);
            host.Open();

            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
            IWampChannel wampChannel = channelFactory.CreateJsonChannel(serverAddress, "vivego", new TicketAuthenticator());

            wampChannel.Open().Wait();

            using (wampChannel.RealmProxy.Services
                   .GetSubject <object>("vivego")
                   .Subscribe(s => { Console.Out.WriteLine(s); }))
            {
                //while (true)
                {
                    string input = Console.ReadLine();

                    realm.TopicContainer.Publish(WampObjectFormatter.Value,
                                                 new PublishOptions(),
                                                 "vivego",
                                                 new object[] { "Helo" });
                }
            }

            wampChannel.Close();

            Console.ReadLine();
        }