Inheritance: Connection
コード例 #1
0
        static void Main(string[] args)
        {
            // Debug.Listeners.Add(new ConsoleTraceListener());

            string _sessionCode = args.Length > 0 ? args[0] : "4575";
            string _url = args.Length > 1 ? args[1] : "http://localhost:62190/";

            HubConnection _conn = new HubConnection(_url);
            IHubProxy _proxy = _conn.CreateProxy("digitalClass");

            _proxy.Subscribe("invokeCommand").Data += data => {
                if (data == null || data.Length == 0)
                    return;

                JToken _first = data[0] as JToken;

                if (_first["command"].ToString() == "PauseActivity")
                    Console.WriteLine("Pause Game");

                if (_first["command"].ToString() == "ResumeActivity")
                    Console.WriteLine("Resume Game");

                if (_first["command"].ToString() == "ClosePresentation")
                    Console.WriteLine("Close Game");
            };

            _conn.Start();
            _proxy.Invoke("JoinFromGame", _sessionCode);

            // wait for push message
            while (true) { };
        }
コード例 #2
0
    void StartSignalR()
    {
        if (_hubConnection == null)
        {
            _hubConnection = new HubConnection(signalRUrl);

            _hubProxy = _hubConnection.CreateProxy("MyHub");
            _subscription = _hubProxy.Subscribe("executeCommand");
            _subscription.Data += data =>
            {
                Debug.Log(data[0].ToString());

                var message = Newtonsoft.Json.JsonConvert.DeserializeObject<Message>(data[0].ToString());

                ActionTrigger = message;
            };
            try
            {
                _hubConnection.Start();
            }
            catch (Exception ex)
            {

            }
        }
        else
        {
            Debug.Log("Signalr already connected...");
        }
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: robink-teleopti/SignalR
        static void Main(string[] args)
        {
            var hubConnection = new HubConnection("http://localhost:40476/");
            RunDemoHub(hubConnection);

            //RunStreamingSample();

            Console.ReadKey();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: robink-teleopti/SignalR
        private static void RunDemoHub(HubConnection hubConnection)
        {
            var demo = hubConnection.CreateProxy("demo");

            demo.Subscribe("invoke").Data += i =>{
                Console.WriteLine("{0} client state index -> {1}", i[0], demo["index"]);
            };

            hubConnection.Start();

            demo.Invoke("multipleCalls");

            Thread.Sleep(7000);
            hubConnection.Stop();
        }
コード例 #5
0
    void StartSignalR()
    {
        if (_hubConnection == null)
        {
            _hubConnection = new HubConnection(signalRUrl);

            _hubProxy = _hubConnection.CreateProxy("SignalRSampleHub");
            _subscription = _hubProxy.Subscribe("broadcastMessage");
            _subscription.Data += data =>
            {
                Debug.Log("signalR called us back");
            };
            _hubConnection.Start();
        }
        else
            Debug.Log("Signalr already connected...");

    }
コード例 #6
0
        private void _ThreadedStartConnection()
        {
            var startedConnection = new HubConnection(_url);

            var startedProxy = startedConnection.CreateProxy(_hubName);

            startedConnection.Start();

            lock (_connLock)
            {
                _proxy = startedProxy;
                _connection = startedConnection;

                _connection.Reconnected += ReconnectedAction;
                _connection.Received += ReceivedAction;
                _connection.Error += ErrorAction;
                _connection.Closed += ClosedAction;
                _connState = ConnectionState.Running;
            }
            lock (ResultQueue)
            {
                ResultQueue.Enqueue(OnConnected);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            // uncomment below to stream debug into console
            // Debug.Listeners.Add(new ConsoleTraceListener());

            // this is an optional query parameters to sent with each message
            var query = new Dictionary<string, string>();
            query.Add("version", "1.0");

            // initialize connection and its proxy
            HubConnection connection = new HubConnection("http://localhost:58438/", query);
            IHubProxy proxy = connection.CreateProxy("TestHub");

            // subscribe to event
            proxy.Subscribe("Pong").Data += data =>
            {
                var _first = data[0] as JToken;
                Console.WriteLine("Received: [{0}] from {1}",
                    _first["message"].ToString(), _first["from"].ToString());
            };

            Console.Write("Connecting... ");
            connection.Start();
            Console.WriteLine("done. Hit: ");
            Console.WriteLine("1:\tSend hello message");
            Console.WriteLine("2:\tRequest => Reply with dynamic reply");
            Console.WriteLine("3:\tRequest => Reply with value type");
            Console.WriteLine("Esc:\tExit");
            Console.WriteLine("");

            var _exit = false;
            while (!_exit)
            {
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.D1:
                        Console.Write("Sending hi... ");
                        proxy.Invoke("Ping", Environment.UserName).Finished += (sender, e) =>
                        {
                            Console.WriteLine("done");
                        };
                        break;
                    case ConsoleKey.D2:
                        Console.Write("Sending request... ");
                        proxy.Invoke("RequestReplyDynamic").Finished += (sender, e) =>
                        {
                            var _first = e.Result as JToken;
                            Console.WriteLine(" got reply [{0}]", _first["time"].ToString());
                        };
                        break;
                    case ConsoleKey.D3:
                        Console.Write("Sending request... ");
                        proxy.Invoke("RequestReplyValueType").Finished += (sender, e) =>
                        {
                            Console.WriteLine("got reply  [{0}]", e.Result);
                        };
                        break;
                    case ConsoleKey.Escape:
                        _exit = true;
                        break;
                }
            }
        }