public void AuthenticatorSendsDetailsToHello() { WampClientPlayground playground = new WampClientPlayground(); CustomAuthenticator authenticator = new CustomAuthenticator { AuthenticationId = "peter", AuthenticationMethods = new string[] { "ticket" } }; HelloMock mock = new HelloMock(); JTokenJsonBinding jsonBinding = new JTokenJsonBinding(); IWampChannel channel = playground.GetChannel (mock, "realm1", jsonBinding, authenticator); channel.Open(); IDictionary <string, ISerializedValue> deserializedDetails = mock.Details.OriginalValue.Deserialize <IDictionary <string, ISerializedValue> > (); Assert.That(deserializedDetails["authmethods"].Deserialize <string[]>(), Is.EquivalentTo(authenticator.AuthenticationMethods)); Assert.That(deserializedDetails["authid"].Deserialize <string>(), Is.EquivalentTo(authenticator.AuthenticationId)); }
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(); }
public async Task InMemoryTest() { var transport = new InMemoryTransport(Scheduler.Default); var binding = new JTokenJsonBinding(); var realm = "some.realm"; var router = new WampHost(); router.RegisterTransport(transport, new[] { binding }); router.Open(); var calleeConnection = transport.CreateClientConnection(binding, Scheduler.Default); WampChannelFactory factory = new WampChannelFactory(); var callee = factory.CreateChannel(realm, calleeConnection, binding); await callee.Open(); await callee.RealmProxy.Services.RegisterCallee(new WampTest()); var callerConnection = transport.CreateClientConnection(binding, Scheduler.Default); var caller = factory.CreateChannel(realm, callerConnection, binding); await caller.Open(); var proxy = caller.RealmProxy.Services.GetCalleeProxy <IWampTest>(); var result = await proxy.Echo("1"); Assert.That(result, Is.EqualTo("1")); await caller.Close(WampErrors.CloseNormal, new GoodbyeDetails()); await callee.Close(WampErrors.CloseNormal, new GoodbyeDetails()); router.Dispose(); }
static void Main(string[] args) { Console.WriteLine("Infra.CNC.Simulator 1.0"); const string location = "ws://127.0.0.1:4099/"; var simulator = new Simulator(); using (IWampHost host = new WampHost()) { var jsonSerializer = JsonSerializer.Create(); jsonSerializer.ContractResolver = new CamelCasePropertyNamesContractResolver(); IWampBinding jsonBinding = new JTokenJsonBinding(jsonSerializer); host.RegisterTransport(new FleckWebSocketTransport(location), jsonBinding); IWampHostedRealm realm = host.RealmContainer.GetRealmByName("infra.cncService.simulator"); // Host WAMP application components host.Open(); Console.WriteLine("Server is running on " + location); realm.Services.RegisterCallee(new ServerInformationService()).Wait(); Console.WriteLine("Registered server information service"); Console.WriteLine("Press any key to send CNC data (x to exit)"); var choise = Console.ReadKey().KeyChar; var subject = realm.Services.GetSubject <ISimulatorValue>("cncData"); while (choise != 'x' && choise != 'X') { simulator.GenerateValues(); subject.OnNext(simulator.Root); Console.WriteLine("Data was sent!"); choise = Console.ReadKey().KeyChar; } Console.WriteLine(Environment.NewLine + "Goodbye"); Console.ReadLine(); } }
public void Start() { _router = new WampHost(); var jsonBinding = new JTokenJsonBinding(); var msgPack = new JTokenMsgpackBinding(); _router.RegisterTransport(new FleckWebSocketTransport("ws://0.0.0.0:8080/ws"), jsonBinding, msgPack); _router.Open(); var realm = _router.RealmContainer.GetRealmByName("com.weareadaptive.reactivetrader"); realm.HostMetaApiService(); }
/// <inheritdoc /> public void Start() { // Open channel to poloniex var mJsonBinding = new JTokenJsonBinding(); Func <IControlledWampConnection <JToken> > connectionFactory = () => new WebSocket4NetTextConnection <JToken>(ServerAddress, mJsonBinding); _channel = _wampChannelFactory.CreateChannel("realm1", connectionFactory, mJsonBinding); _channel.RealmProxy.Monitor.ConnectionBroken += OnConnectionBroken; _channel.RealmProxy.Monitor.ConnectionEstablished += OnConnectionEstablised; _channel.RealmProxy.Monitor.ConnectionError += OnConnectionError; _channel.Open().Wait(5000); Logger.Info("Poloniex ticker service has been started"); }
/// <inheritdoc /> public void Start() { // Open channel to poloniex var mJsonBinding = new JTokenJsonBinding(); Func <IControlledWampConnection <JToken> > connectionFactory = () => new WebSocket4NetTextConnection <JToken>(ServerAddress, mJsonBinding); _channel = _wampChannelFactory.CreateChannel("realm1", connectionFactory, mJsonBinding); _channel.RealmProxy.Monitor.ConnectionBroken += OnConnectionBroken; _channel.Open().Wait(5000); // Subscribe to ticker topic _subscription = _channel.RealmProxy.Services.GetSubject(TickerTopic).Subscribe(x => ProcessTick(x.Arguments)); Logger.Info("Poloniex ticker service has been started"); }
public void AuthenticatorAuthenticateResultCallsAuthenticate() { WampClientPlayground playground = new WampClientPlayground(); CustomAuthenticator authenticator = new CustomAuthenticator (delegate { return(new AuthenticationResponse() { Extra = new MyAuthenticateExtraData() { Secret1 = 3 }, Signature = "secretsignature" }); }) { AuthenticationId = "peter", AuthenticationMethods = new string[] { "ticket" } }; AuthenticateMock mock = new AuthenticateMock("ticket"); JTokenJsonBinding jsonBinding = new JTokenJsonBinding(); IWampChannel channel = playground.GetChannel (mock, "realm1", jsonBinding, authenticator); channel.Open(); Assert.That(mock.Signature, Is.EqualTo("secretsignature")); IDictionary <string, ISerializedValue> deserializedExtra = mock.Extra.OriginalValue.Deserialize <IDictionary <string, ISerializedValue> >(); Assert.That(deserializedExtra["secret1"].Deserialize <int>(), Is.EqualTo(3)); }
public void AuthenticatorAuthenticateExceptionCallsAbort() { WampClientPlayground playground = new WampClientPlayground(); MyAbortDetails myAbortDetails = new MyAbortDetails() { Message = "My message", User = "******" }; CustomAuthenticator authenticator = new CustomAuthenticator (delegate { throw new WampAuthenticationException(myAbortDetails, "some reason"); }) { AuthenticationId = "peter", AuthenticationMethods = new string[] { "ticket" } }; AbortMock mock = new AbortMock("ticket"); JTokenJsonBinding jsonBinding = new JTokenJsonBinding(); IWampChannel channel = playground.GetChannel (mock, "realm1", jsonBinding, authenticator); channel.Open(); Assert.That(mock.Reason, Is.EqualTo("some reason")); MyAbortDetails deserializedDetails = mock.Details.OriginalValue.Deserialize <MyAbortDetails>(); Assert.That(deserializedDetails, Is.EqualTo(myAbortDetails)); }
public void AuthenticatorGetsChallengeMessage() { WampClientPlayground playground = new WampClientPlayground(); CustomAuthenticator authenticator = new CustomAuthenticator { AuthenticationId = "peter", AuthenticationMethods = new string[] { "ticket" } }; MyChallengeDetails myChallengeDetails = new MyChallengeDetails() { MyNumber = 3 }; ChallengeMock mock = new ChallengeMock("ticket", myChallengeDetails); JTokenJsonBinding jsonBinding = new JTokenJsonBinding(); IWampChannel channel = playground.GetChannel (mock, "realm1", jsonBinding, authenticator); channel.Open(); Assert.That(authenticator.AuthMethod, Is.EqualTo("ticket")); Assert.That(authenticator.Extra.OriginalValue.Deserialize <MyChallengeDetails>(), Is.EqualTo(myChallengeDetails)); }
private async Task OpenConnectionAndSub() { await Task.Run(async() => { // Connect // Subscribe // Await // Unsub while (!this.cancelToken.IsCancellationRequested) { this.tcs = new TaskCompletionSource <int>(); this.isConnected = false; // Connect // var binding = new JTokenJsonBinding(); Func <IControlledWampConnection <JToken> > connectionFactory = () => new ControlledTextWebSocketConnection <JToken>(new Uri(this.settings.Address), binding); this.channel = new WampChannelFactory().CreateChannel(this.settings.Realm, connectionFactory, binding); var monitor = this.channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnConnectionBroken; monitor.ConnectionError += OnConnectionError; while (!monitor.IsConnected && !this.cancelToken.IsCancellationRequested) { try { this.log?.WriteInfoAsync(nameof(WampSubscriber <T>), nameof(Start), string.Empty, $"Trying to connect to server: {this.settings.Address} realm: {this.settings.Realm}"); await this.channel.Open(); } catch (Exception ex) { this.log?.WriteErrorAsync(nameof(WampSubscriber <T>), nameof(Start), string.Empty, ex); this.log?.WriteInfoAsync(nameof(WampSubscriber <T>), nameof(Start), string.Empty, "Retrying to connect in 5 sec..."); await Task.Delay(5000); } } // Subscribe to topics // if (!this.cancelToken.IsCancellationRequested) { this.log?.WriteInfoAsync(nameof(WampSubscriber <T>), nameof(Start), string.Empty, $"Connected to server {this.settings.Address}"); foreach (var topic in this.settings.Topics) { var subj = this.channel.RealmProxy.Services.GetSubject <T>(topic); this.subscriptions.Add(subj.Subscribe(this.OnNext, this.OnError, this.OnCompleted)); this.log?.WriteInfoAsync(nameof(WampSubscriber <T>), nameof(Start), string.Empty, $"Subscribed to topic '${topic}'."); } this.isConnected = true; await tcs.Task; } // Unsub CloseConnection(); } }); }
public async Task ExecuteAsync(IConsole console) { WampHost wampHost = new WampHost(); JTokenJsonBinding jsonBinding = new JTokenJsonBinding(); JTokenCborBinding cborBinding = new JTokenCborBinding(); JTokenMessagePackBinding messagePackBinding = new JTokenMessagePackBinding(); IWebHost host = WebHost.CreateDefaultBuilder() .UseKestrel(options => { options.Listen(IPAddress.Loopback, Port, builder => { // Log all of the http bytes as they are sent and received builder.UseConnectionLogging(); // Configure RawSocket transport wampHost .RegisterTransport(new AspNetCoreRawSocketTransport(builder), jsonBinding, cborBinding, messagePackBinding); }); }) .Configure(app => { app.Map("/ws", builder => { builder.UseWebSockets(); // Configure WebSockets transport wampHost .RegisterTransport(new AspNetCoreWebSocketTransport(builder, null), jsonBinding, cborBinding, messagePackBinding); }); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path .Combine(Directory.GetCurrentDirectory(), "static")), RequestPath = "" }); app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileProvider = new PhysicalFileProvider(Path .Combine(Directory.GetCurrentDirectory(), "static")), RequestPath = "" }); wampHost.Open(); }) .Build(); await host.RunAsync().ConfigureAwait(false); }