示例#1
0
        static void Main(string[] args)
        {
            // Sample modeled and compatible with Autobahn Python https://github.com/tavendo/AutobahnPython [examples/twisted/wamp1/authentication/server.py]

            const string location = "ws://127.0.0.1:9000/";

            using (IWampHost host = new DefaultWampCraHost(location, new SampleWampCraAuthenticaticationBuilder <JToken>()))
            {
                ISample instance = new Sample();
                host.HostService(instance);

                host.Open();

                Console.WriteLine("Server is running on " + location);

                //publish just for kicks.
                IWampTopic topic = host.TopicContainer.GetOrCreateTopicByUri("http://example.com/topics/mytopic1", true);
                while (true)
                {
                    Thread.Sleep(2000);
                    if (topic.HasObservers)
                    {
                        topic.OnNext("Hello, world!");
                    }
                }

                Console.ReadLine();
            }
        }
示例#2
0
        public void TopicOnNextCallsSubjectOnNext()
        {
            WampPlayground playground = new WampPlayground();

            IWampHost host = playground.Host;

            IWampTopicContainer topicContainer = host.TopicContainer;

            host.Open();

            IWampChannel <MockRaw> channel =
                playground.CreateNewChannel();

            channel.Open();

            IWampTopic topic = null;

            topicContainer.TopicCreated +=
                (sender, args) => topic  = args.Topic;

            object            @event   = null;
            string            topicUri = "http://example.com/simple";
            ISubject <object> subject  = channel.GetSubject <object>(topicUri);

            subject.Subscribe(x => @event = x);

            Assert.That(topic, Is.Not.Null);
            Assert.That(topic.TopicUri, Is.EqualTo(topicUri));

            string value = "Test :)";

            topic.OnNext(value);

            Assert.That(@event, Is.EqualTo(value));
        }
示例#3
0
 //remove messages
 public void PublishRemove()
 {
     if (RemoteContext.HasRemoveElements())
     {
         var json = RemoteContext.GetRemoveJson();
         FRemoveTopic.OnNext(json);
     }
 }
示例#4
0
 //add messages
 public void PublishAdd()
 {
     if (RemoteContext.HasAddElements())
     {
         var xml = RemoteContext.GetAddXML();
         FAddTopic.OnNext(xml);
     }
 }
示例#5
0
 //publish json massage with updated attributes
 public void PublishContent()
 {
     if (RemoteContext.HasContentUpdates())
     {
         var json = RemoteContext.GetContentUpdateJson();
         FUpdateContentTopic.OnNext(json);
     }
 }
示例#6
0
 //publish json massage with updated attributes
 public void PublishUpdate()
 {
     if (RemoteContext.HasAttributeUpdates())
     {
         var json = RemoteContext.GetAttributeUpdateJson();
         FUpdateAttributeTopic.OnNext(json);
     }
 }
示例#7
0
        public void Publish(string topicUri, TMessage @event, string[] exclude, string[] eligible)
        {
            lock (mLock)
            {
                IWampTopic topic = GetTopicByUri(topicUri);

                if (topic != null)
                {
                    topic.OnNext(new WampNotification(@event, exclude, eligible));
                }
            }
        }