예제 #1
0
        static void Main(string[] args)
        {
            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();

            IWampChannel <JToken> channel =
                channelFactory.CreateChannel("ws://127.0.0.1:9000/");

            channel.Open();

            ICalculator proxy = channel.GetRpcProxy <ICalculator>();

            int five = proxy.Add(2, 3);

            Console.WriteLine("2 + 3 = " + five);

            IAsyncCalculator asyncProxy =
                channel.GetRpcProxy <IAsyncCalculator>();

            Task <int> asyncFive =
                asyncProxy.Add(2, 3);

            Console.WriteLine("2 + 3 = " + asyncFive.Result);

            Console.ReadLine();
        }
예제 #2
0
        private static void ClientCode(string serverAddress, MethodInfo sampleMethod)
        {
            JTokenJsonBinding binding = new JTokenJsonBinding();

            DefaultWampChannelFactory factory =
                new DefaultWampChannelFactory();

            IWampChannel channel =
                factory.CreateChannel(serverAddress, "realm1", binding);

            Task task = channel.Open();

            task.Wait(5000);

            if (!task.IsCompleted)
            {
                Console.WriteLine("Server might be down.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadLine();
                Environment.Exit(0);
            }
            else
            {
                Console.WriteLine("Connected to server.");
            }

            sampleMethod.Invoke(null, new object[] { channel.RealmProxy.Services });

            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            //Sample modeled and compatible with Autobahn Python https://github.com/tavendo/AutobahnPython [examples/twisted/wamp1/authentication/client.py]

            JsonSerializer            serializer     = new JsonSerializer();
            JsonFormatter             formatter      = new JsonFormatter(serializer);
            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(serializer);
            IWampChannel <JToken>     channel        = channelFactory.CreateChannel("ws://127.0.0.1:9000/");

            channel.Open();

            try
            {
                IWampCraProcedures proxy = channel.GetRpcProxy <IWampCraProcedures>();

                //TODO: This can authenticates as a user, or as anonymous based on conditional.
                WampCraPermissions permissions;
                if (true)
                {
                    permissions = Authenticate(proxy, formatter, "foobar", null, "secret");
                }
                else
                {
                    permissions = Authenticate(proxy, formatter, null, null, null);
                }

                Console.WriteLine("permissions: {0}", formatter.Serialize(permissions));
            }
            catch (WampRpcCallException ex)
            {
                Console.Out.WriteLine("Authenticate WampRpcCallException: '{0}' to uri '{1}'", ex.Message,
                                      ex.ProcUri);
            }

            try
            {
                //Expect failure if running against default server sample and anonymous.

                ISample proxy  = channel.GetRpcProxy <ISample>();
                string  result = proxy.Hello("Foobar");
                Console.WriteLine(result);
            }
            catch (WampRpcCallException ex)
            {
                Console.Out.WriteLine("Hello WampRpcCallException: '{0}' to uri '{1}'", ex.Message,
                                      ex.ProcUri);
            }

            //server sample allows for subscribe for anon and foobar user.
            ISubject <string> subject     = channel.GetSubject <string>("http://example.com/topics/mytopic1");
            IDisposable       cancelation = subject.Subscribe(x => Console.WriteLine("mytopic1: " + x));

            //server sample does not allow for publish if anon.  Therefore, if logged in, expect to see
            // this in console, otherwise it will silently fail to publish (Wamp1 makes it silent).
            subject.OnNext("Hello World From Client!");

            Console.ReadLine();
            channel.Close();
        }
예제 #4
0
        static void Main(string[] args)
        {
            //Sample modeled and compatible with Autobahn Python https://github.com/tavendo/AutobahnPython [examples/twisted/wamp1/authentication/client.py]

            JsonFormatter formatter = new JsonFormatter();
            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(formatter);
            IWampChannel<JToken> channel = channelFactory.CreateChannel("ws://localhost:9000/");

            channel.Open();

            try
            {
                IWampCraProcedures proxy = channel.GetRpcProxy<IWampCraProcedures>();

                //TODO: This can authenticates as a user, or as anonymous based on conditional.
                WampCraPermissions permissions;
                if (true)
                {
                    permissions = Authenticate(proxy, formatter, "foobar", null, "secret");
                }
                else
                {
                    permissions = Authenticate(proxy, formatter, null, null, null);
                }

                Console.WriteLine("permissions: {0}", formatter.Serialize(permissions));
            }
            catch (WampRpcCallException ex)
            {
                Console.Out.WriteLine("Authenticate WampRpcCallException: '{0}' to uri '{1}'", ex.Message,
                                      ex.ProcUri);
            }

            try
            {
                //Expect failure if running against default server sample and anonymous.

                ISample proxy = channel.GetRpcProxy<ISample>();
                string result = proxy.Hello("Foobar");
                Console.WriteLine(result);
            }
            catch (WampRpcCallException ex)
            {
                Console.Out.WriteLine("Hello WampRpcCallException: '{0}' to uri '{1}'", ex.Message,
                                      ex.ProcUri);
            }

            //server sample allows for subscribe for anon and foobar user.
            ISubject<string> subject = channel.GetSubject<string>("http://example.com/topics/mytopic1");
            IDisposable cancelation = subject.Subscribe(x => Console.WriteLine("mytopic1: " + x));

            //server sample does not allow for publish if anon.  Therefore, if logged in, expect to see
            // this in console, otherwise it will silently fail to publish (Wamp1 makes it silent).
            subject.OnNext("Hello World From Client!");

            Console.ReadLine();
            channel.Close();
        }
예제 #5
0
        public void SubscribeAndWait(int workTimeMillis = 85)
        {
            var factory = new DefaultWampChannelFactory();
            var binding = new JTokenMsgpackBinding();

            var channel = factory.CreateChannel("realm", new WebSocket4NetBinaryConnection <JToken>(Configs.ServerAddress, binding), binding);

            try
            {
                channel.Open().Wait();
                //
                for (var i = 0; i < Configs.N_SUBJECTS; i++)
                {
                    string topicUri = Configs.SUBJECT_ + i;
                    channel.RealmProxy.Services.GetSubject <WsEvent>(topicUri).Subscribe(
                        @event =>
                    {
                        Interlocked.Add(ref EventsConsumed, 1);
                        //
                        if (@event.Id % 100 == 0)
                        {
                            Logger.Info("Client #" + _id + ". Processing event #" + @event.Id);
                        }
                        //
                        Thread.Sleep(workTimeMillis);
                    },
                        ex =>
                    {
                        Logger.Error($"Error during {topicUri} subscription", ex);
                    });
                }
                //
                while (!_shouldTerminate())
                {
                    Thread.Sleep(1);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in Client #" + _id, ex);
                // ReSharper disable once LocalizableElement
                MessageBox.Show("Error in Client #" + _id + "\r\n\r\n" + ex, "Error");
                Application.Exit();
            }
            finally
            {
                channel.Close("Test complete", new GoodbyeDetails()
                {
                    Message = "Client #" + _id
                });
            }
        }
예제 #6
0
        public void BuildChannel()
        {
            logger.Info("Start building channel with " + "ws://" + pushServer);

            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
            IWebProxy iProxy = session.GetApiClient().Configuration.ApiClient.RestClient.Proxy;

            if (iProxy != null)
            {
                WebProxy          proxy       = iProxy as WebProxy;
                NetworkCredential credentials = proxy.Credentials as NetworkCredential;

                channel = channelFactory.CreateChannel("ws://" + pushServer, proxy.Address.Host, proxy.Address.Port, credentials.UserName, credentials.Password);
            }
            else
            {
                channel = channelFactory.CreateChannel("ws://" + pushServer);
                Console.WriteLine(channel);
            }

            logger.Info("Successfully building channel with " + "ws://" + pushServer);
        }
예제 #7
0
 public void Connect()
 {
     DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
     this.serverws = channelFactory.CreateChannel(Manager.wsUrl);
     try
     {
         serverws.Open();
         this.ServeurIsConnected = true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         this.ServeurIsConnected = false;
     }
 }
예제 #8
0
        public void Connect()
        {
            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();

            this.serverws = channelFactory.CreateChannel(Manager.wsUrl);
            try
            {
                serverws.Open();
                this.ServeurIsConnected = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                this.ServeurIsConnected = false;
            }
        }
예제 #9
0
        public Client()
        {
            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
            IWampChannel<JToken> channel = channelFactory.CreateChannel("ws://projetx.nordri.fr:8080/");
            channel.Open();

            // PubSub subscription:
            ISubject<CommonUserLogin> subject = channel.GetSubject<CommonUserLogin>("ws.projetx.common.user.login");
            IDisposable subscription = subject.Subscribe(x => Console.WriteLine("Received " + x));

            CommonUserLogin cul = new CommonUserLogin()
                        {
                            topic="ws.projetx",
                            data = new CommonUserLoginData() {TimeStamp=0,UserEmail="victorien.vanroye",UserId=0,Username="******"},
                        };
            Console.Write(JsonConvert.SerializeObject(cul));
        }
예제 #10
0
        public Client()
        {
            DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
            IWampChannel <JToken>     channel        = channelFactory.CreateChannel("ws://projetx.nordri.fr:8080/");

            channel.Open();

            // PubSub subscription:
            ISubject <CommonUserLogin> subject = channel.GetSubject <CommonUserLogin>("ws.projetx.common.user.login");
            IDisposable subscription           = subject.Subscribe(x => Console.WriteLine("Received " + x));

            CommonUserLogin cul = new CommonUserLogin()
            {
                topic = "ws.projetx",
                data  = new CommonUserLoginData()
                {
                    TimeStamp = 0, UserEmail = "victorien.vanroye", UserId = 0, Username = "******"
                },
            };

            Console.Write(JsonConvert.SerializeObject(cul));
        }
예제 #11
0
        public void SubscribeAndWait(int workTimeMillis = 85)
        {
            var factory = new DefaultWampChannelFactory();
            var binding = new JTokenMsgpackBinding();

            var channel = factory.CreateChannel("realm", new WebSocket4NetBinaryConnection<JToken>(Configs.ServerAddress, binding), binding);
            try
            {
                channel.Open().Wait();
                //
                for (var i = 0; i < Configs.N_SUBJECTS; i++)
                {
                    string topicUri = Configs.SUBJECT_ + i;
                    channel.RealmProxy.Services.GetSubject<WsEvent>(topicUri).Subscribe(
                        @event =>
                        {
                            Interlocked.Add(ref EventsConsumed, 1);
                            //
                            if (@event.Id%100 == 0)
                            {
                                Logger.Info("Client #" + _id + ". Processing event #" + @event.Id);
                            }
                            //
                            Thread.Sleep(workTimeMillis);
                        },
                        ex =>
                        {
                            Logger.Error($"Error during {topicUri} subscription", ex);
                        });
                }
                //
                while (!_shouldTerminate())
                {
                    Thread.Sleep(1);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in Client #" + _id, ex);
                // ReSharper disable once LocalizableElement
                MessageBox.Show("Error in Client #" + _id + "\r\n\r\n" + ex, "Error");
                Application.Exit();
            }
            finally
            {
                channel.Close("Test complete", new GoodbyeDetails()
                {
                    Message = "Client #" + _id
                });
            }
        }