Пример #1
0
    void Start()
    {
        // Create the hubs
        demoHub      = new DemoHub();
        typedDemoHub = new TypedDemoHub();
        vbDemoHub    = new Hub("vbdemo");

        // Create the SignalR connection, passing all the three hubs to it
        signalRConnection = new Connection(URI, demoHub, typedDemoHub, vbDemoHub);

        // Switch from the default encoder to the LitJson Encoder becouse it can handle the complex types too.
        signalRConnection.JsonEncoder = new LitJsonEncoder();

        // Call the demo functions when we successfully connect to the server
        signalRConnection.OnConnected += (connection) =>
        {
            var person = new { Name = "Foo", Age = 20, Address = new { Street = "One Microsoft Way", Zip = "98052" } };

            // Call the demo functions

            demoHub.AddToGroups();
            demoHub.GetValue();
            demoHub.TaskWithException();
            demoHub.GenericTaskWithException();
            demoHub.SynchronousException();
            demoHub.DynamicTask();
            demoHub.PassingDynamicComplex(person);
            demoHub.SimpleArray(new int[] { 5, 5, 6 });
            demoHub.ComplexType(person);
            demoHub.ComplexArray(new object[] { person, person, person });
            demoHub.ReportProgress("Long running job!");

            demoHub.Overload();

            // set some state
            demoHub.State["name"] = "Testing state!";
            demoHub.ReadStateValue();

            demoHub.PlainTask();
            demoHub.GenericTaskWithContinueWith();

            typedDemoHub.Echo("Typed echo callback");

            // vbDemo is not wrapped in a hub class, it would contain only one function
            vbDemoHub.Call("readStateValue", (hub, msg, result) => vbReadStateResult = string.Format("Read some state from VB.NET! => {0}", result.ReturnValue == null ? "undefined" : result.ReturnValue.ToString()));
        };

        // Start opening the signalR connection
        signalRConnection.Open();
    }
Пример #2
0
    public void Send()
    {
        string msg = input.text;

        _proxy.Call("Broadcast", msg);
    }