protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);

            //This is all you need to do in android project
            WebsocketInitializer.SetPlatform(PlatformName.Android);

            LoadApplication(new App());
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            WebsocketInitializer.SetPlatform(PlatformName.Android);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var button = FindViewById <Button>(Resource.Id.buttonSubscribe);

            button.Click += delegate {
                Subscribe();
            };
        }
        public async void RunAsync()
        {
            //set platform assembly (Optional)
            WebsocketInitializer.SetPlatform(PlatformName.Desktop);

            var socket = new JsonWebsocketClient(new Uri(Uri));

            socket.StatusStream.Subscribe(value =>
            {
                Console.WriteLine(value.ConnectionState != ConnectionState.Disconnected
                    ? $"Status: {value.ConnectionState}; {value.Message}"
                    : $"Status: {value.ConnectionState}; {value.Error?.Message}");
            });

            var success = await socket.ConnectAsync();

            if (!success)
            {
                return;
            }

            var inputData = new Data()
            {
                Id      = Guid.NewGuid().ToString(),
                Number1 = 100,
                Number2 = 200
            };

            Console.WriteLine("Sending request to server: ");

            var result = await socket.GetResponse <Data, Result>(inputData, result1 => result1.Id.Equals(inputData.Id));

            socket.GetObservable <Data, Result>(inputData, result1 => result1.Id.Equals(inputData.Id))
            .Subscribe(resultReceived =>
            {
                Console.WriteLine($"Result received from server {resultReceived.Value}");
            },
                       exception =>
            {
                Console.WriteLine($"Error: {exception.Message}");
            });
        }
        public async void RunAsync()
        {
            //set platform assembly (Optional)
            WebsocketInitializer.SetPlatform(PlatformName.Desktop);

            // Use the StringWebsocketClient for simple string payloads
            var socket = new StringWebsocketClient(new Uri(Uri));

            socket.StatusStream.Subscribe(value =>
            {
                Console.WriteLine(value.ConnectionState != ConnectionState.Disconnected
                    ? $"Status: {value.ConnectionState}; {value.Message}"
                    : $"Status: {value.ConnectionState}; {value.Error?.Message}");
            });

            var success = await socket.ConnectAsync();

            if (!success)
            {
                return;
            }

            const string request = "test";

            Console.WriteLine("Sending request to server: " + request);

            var result = await socket.GetResponse(request, s => true);


            socket.GetObservable(request, s => true)
            .Subscribe(value =>
            {
                Console.WriteLine($"Message received from server {value}");
            },
                       exception =>
            {
                Console.WriteLine($"Error: {exception.Message}");
            });
        }