示例#1
0
        static void Main(string[] args)
        {
            // Like opening a browser
            Workspace w = new Workspace();

            // Enable network connections
            w.AddURIHandler(new WebSocketURIHandler());

            // Get live array of numbers through WebSocket
            string        uri = "ws://test.objectfabric.org/array";
            TArray <long> a   = (TArray <long>)w.Open(uri).Value;

            // Add a listener on array, called when an element is
            // set to a new value server side
            a.Set += i =>
            {
                switch (i)
                {
                case 0:
                    Console.WriteLine("World population: " + a[i]);
                    break;

                case 1:
                    Console.WriteLine("Internet Users: " + a[i]);
                    break;
                }
            };
        }
示例#2
0
        static void Main(string[] args)
        {
            // Like opening a browser
            Workspace w = new Workspace();

            // Enables network connections
            w.AddURIHandler(new WebSocketURIHandler());

            // Get a room
            Resource      resource = w.Open("ws://localhost:8888/room1");
            TSet <string> messages = (TSet <string>)resource.Value;

            // A room is a set of messages. Adding a message to a
            // set raises the 'Added' event on all clients who
            // share the the same URI

            // Display messages that get added to the set
            messages.Added += s =>
            {
                Console.WriteLine(s);
            };

            // Listen for typed messages and add them to the set
            Console.Write("my name? ");
            string me = Console.ReadLine();

            messages.Add("New user: "******": " + s);
            }
        }
示例#3
0
        async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Workspace workspace = new Workspace();

            workspace.AddURIHandler(new WebSocketURIHandler());
            resource = await workspace.OpenAsync("ws://localhost:8888/images");

            DispatcherTimer dispatcherTimer = new DispatcherTimer();

            dispatcherTimer.Tick    += Refresh;
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(100);
            dispatcherTimer.Start();

            positions        = (TSet <TArray <double> >)resource.Value;
            button.IsEnabled = true;

            // Register a handler on the set to be notified when an image
            // is added that needs to be displayed.
            positions.Added += (item) =>
            {
                AddImageToUI((TArray <double>)item);
            };

            // Some images might already be shared, show them. Use an atomic
            // block to get a stable view of the collection.
            workspace.Atomic(() =>
            {
                foreach (TArray <double> position in positions)
                {
                    AddImageToUI(position);
                }
            });
        }
示例#4
0
        static void Main(string[] args)
        {
            Workspace workspace = new Workspace();

            workspace.AddURIHandler(new WebSocketURIHandler());

            /*
             * Fetch resource from server. (Server java\src\main\java\launchfirst\SamplesServer.java must be running)
             */
            object value = workspace.Open("ws://localhost:8888/helloworld").Value;

            Console.WriteLine(value);

            Console.ReadLine();
        }
示例#5
0
        static void Main(string[] args)
        {
            Workspace workspace = new Workspace();

            workspace.AddURIHandler(new WebSocketURIHandler());

            TDictionary <object, object> map = (TDictionary <object, object>)workspace.Open("ws://localhost:8888/map").Value;

            map.Added += key =>
            {
                Console.WriteLine("Added: " + map[key]);
            };

            map["blah"] = "new";

            // TODO finish

            Console.ReadLine();
        }