当前位置: 首页>>代码示例>>C#>>正文


C# HubConnection.Start方法代码示例

本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection.Start方法的典型用法代码示例。如果您正苦于以下问题:C# HubConnection.Start方法的具体用法?C# HubConnection.Start怎么用?C# HubConnection.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNet.SignalR.Client.HubConnection的用法示例。


在下文中一共展示了HubConnection.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectToSignalR

        private async Task ConnectToSignalR()
        {
            hubConnection = new HubConnection(App.MobileService.ApplicationUri.AbsoluteUri);

            if (user != null)
            {
                hubConnection.Headers["x-zumo-auth"] = user.MobileServiceAuthenticationToken;
            }
            else
            {
                hubConnection.Headers["x-zumo-application"] = App.MobileService.ApplicationKey;
            }

            proxy = hubConnection.CreateHubProxy("ChatHub");
            await hubConnection.Start();

            proxy.On<string>("helloMessage", async (msg) =>
             {
                 await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                 {
                     message += " " + msg;
                     Message.Text = message;
                 });

             });
        }
开发者ID:Satur01,项目名称:DemoSignalR,代码行数:26,代码来源:MainPage.cs

示例2: SendToGroupFromOutsideOfHub

        public async Task SendToGroupFromOutsideOfHub()
        {
            using (var host = new MemoryHost())
            {
                IHubContext<IBasicClient> hubContext = null;
                host.Configure(app =>
                {
                    var configuration = new HubConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    app.MapSignalR(configuration);
                    hubContext = configuration.Resolver.Resolve<IConnectionManager>().GetHubContext<SendToSome, IBasicClient>();
                });

                var connection1 = new HubConnection("http://foo/");

                using (connection1)
                {
                    var wh1 = new AsyncManualResetEvent(initialState: false);

                    var hub1 = connection1.CreateHubProxy("SendToSome");

                    await connection1.Start(host);

                    hub1.On("send", wh1.Set);

                    hubContext.Groups.Add(connection1.ConnectionId, "Foo").Wait();
                    hubContext.Clients.Group("Foo").send();

                    Assert.True(await wh1.WaitAsync(TimeSpan.FromSeconds(10)));
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:35,代码来源:GetHubContextFacts.cs

示例3: Main

        static void Main(string[] args)
        {
            Console.Write("Enter your Name: ");
            name = Console.ReadLine();

            HubConnection connection = new HubConnection("http://localhost:51734");
            proxy = connection.CreateHubProxy("ChatHub");

            connection.Received += Connection_Received;

            Action<string, string> SendMessageRecieved = recieved_a_message;

            proxy.On("broadcastMessage", SendMessageRecieved);

            Console.WriteLine("Waiting for connection");
            connection.Start().Wait();
            Console.WriteLine("You can send messages now.");

            connection.StateChanged += Connection_StateChanged;

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                proxy.Invoke("Send", new object[] { name, input });
            }
        }
开发者ID:AlexRex,项目名称:CasualGaming--SignalRChatEx2015,代码行数:26,代码来源:Program.cs

示例4: Run

        public void Run()
        {
            System.Console.WriteLine("Starting connection to host at: {0} with launcher identifier name as {1}", AppSettings.HostUrl, AppSettings.LauncherName);

            var hubConnection = new HubConnection(AppSettings.HostUrl);
            IHubProxy hubProxy = hubConnection.CreateHubProxy("LauncherHub");
            hubProxy.On<LauncherCommand>("sendCommand", OnSendCommand);
            hubProxy.On<IEnumerable<LauncherSequence>>("sendSequence", OnSendSequence);
            ServicePointManager.DefaultConnectionLimit = 10;
            hubConnection.Start().Wait();

            hubConnection.StateChanged += change =>
            {
                System.Console.WriteLine("Connection to host state has changed to : " + change.NewState);
                if (change.NewState == ConnectionState.Connected)
                {
                    hubProxy.Invoke("Initialize", AppSettings.LauncherName);
                }
            };

            hubProxy.Invoke("Initialize", AppSettings.LauncherName);
            System.Console.WriteLine("Connection established.... waiting for commands from host...");
            while (true)
            {
                // let the app know we are health every 1000 (Ms = 1 second) * 60 sec = 1 min *
                Thread.Sleep(1000 * 60 * 5);
                hubProxy.Invoke("Initialize", AppSettings.LauncherName);
            }
        }
开发者ID:travisgosselin,项目名称:desktop-rocket-launcher,代码行数:29,代码来源:HostControlled.cs

示例5: RunHubConnectionAPI

        private async Task RunHubConnectionAPI(string url)
        {
            var hubConnection = new HubConnection(url);
            hubConnection.TraceWriter = _traceWriter;

            var hubProxy = hubConnection.CreateHubProxy("HubConnectionAPI");
            hubProxy.On<string>("displayMessage", (data) => hubConnection.TraceWriter.WriteLine(data));

            await hubConnection.Start();
            hubConnection.TraceWriter.WriteLine("transport.Name={0}", hubConnection.Transport.Name);

            await hubProxy.Invoke("DisplayMessageCaller", "Hello Caller!");

            string joinGroupResponse = await hubProxy.Invoke<string>("JoinGroup", hubConnection.ConnectionId, "CommonClientGroup");
            hubConnection.TraceWriter.WriteLine("joinGroupResponse={0}", joinGroupResponse);

            await hubProxy.Invoke("DisplayMessageGroup", "CommonClientGroup", "Hello Group Members!");

            string leaveGroupResponse = await hubProxy.Invoke<string>("LeaveGroup", hubConnection.ConnectionId, "CommonClientGroup");
            hubConnection.TraceWriter.WriteLine("leaveGroupResponse={0}", leaveGroupResponse);

            await hubProxy.Invoke("DisplayMessageGroup", "CommonClientGroup", "Hello Group Members! (caller should not see this message)");

            await hubProxy.Invoke("DisplayMessageCaller", "Hello Caller again!");
        }
开发者ID:gmahota,项目名称:CRM_MIT,代码行数:25,代码来源:CommonClient.cs

示例6: OpenConnection

 public void OpenConnection()
 {
     _connection = new HubConnection(_hubUrl);
     _alertHubProxy = _connection.CreateHubProxy("alertHub");
     _resourceHubProxy = _connection.CreateHubProxy("resourceHub");
     _connection.Start().Wait();
 }
开发者ID:docrinehart,项目名称:deathstar-imperator,代码行数:7,代码来源:HubClient.cs

示例7: Connect

        private async void Connect()
        {
            Connection = new HubConnection(ServerURI);
            HubProxy = Connection.CreateHubProxy("NotifierHub");

            HubProxy.On<AlarmMessage>("SendNotification", async (notification) =>
            {
                await this.AlarmsList.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.AlarmsList.Items.Add(notification);
                });
            }
            );

            try
            {
                await Connection.Start();
            }
            catch (HttpRequestException)
            {
                return;
            }
            catch (Exception)
            {
                return;
            }
        }
开发者ID:VivendoByte,项目名称:AlarmNotifier,代码行数:27,代码来源:MainPage.xaml.cs

示例8: StartConnection

        private async void StartConnection()
        {
            // Connect to the server
            try
            {
                var hubConnection = new HubConnection("http://192.168.0.43:61893/");

                // Create a proxy to the 'ChatHub' SignalR Hub
                chatHubProxy = hubConnection.CreateHubProxy("ChatHub");

                // Wire up a handler for the 'UpdateChatMessage' for the server
                // to be called on our client
                chatHubProxy.On<string,string>("broadcastMessage", (name, message) => {
                    var str = $"{name}:{message}\n";
                RunOnUiThread(()=>     text.Append( str ) );
                });


                // Start the connection
                await hubConnection.Start();


            }
            catch (Exception e)
            {
                text.Text = e.Message;
            }
        }
开发者ID:Coladela,项目名称:signalr-chat,代码行数:28,代码来源:MainActivity.cs

示例9: GetProxy

 public async static Task<IHubProxy> GetProxy(String hubName)
 {
     var hubConnection = new HubConnection(ConfigurationManager.AppSettings.Get("ServerAddressAndPort"));
     IHubProxy proxy = null;
     switch (hubName)
     {
         case "UserHub":
         {
             proxy = hubConnection.CreateHubProxy("UserHub");
             break;
         }
         case "MessageHub":
         {
             proxy = hubConnection.CreateHubProxy("MessageHub");
             break;
         }
         case "ConversationHub":
         {
             proxy = hubConnection.CreateHubProxy("ConversationHub");
             break;
         }
     }
     ServicePointManager.DefaultConnectionLimit = 20;
     await hubConnection.Start();
     return proxy;
 }
开发者ID:v-silverfin,项目名称:Vjestina-2015-Projekt,代码行数:26,代码来源:DBConnection.cs

示例10: btnCon_Click

        private async Task btnCon_Click(object sender, EventArgs e)
        {
            this.btnInvok.Enabled = false;

            hubConnection = new HubConnection(txtUrl.Text);
            stockTickerHubProxy = hubConnection.CreateHubProxy("TickerHub");
            strongHubProxy = hubConnection.CreateHubProxy("StrongHub");

            this.btnCon.Enabled = false;
            try
            {
                await hubConnection.Start(new WebSocketTransport());

                this.btnInvok.Enabled = true;
            }
            catch (Exception ex)
            {
                Exception temp = ex;
                string msg = temp.Message;
                while (temp.InnerException != null)
                {
                    temp = temp.InnerException;
                    msg += "\r\n" + temp.Message;
                }
                MessageBox.Show(msg);
            }
            this.btnCon.Enabled = true;

        }
开发者ID:Indifer,项目名称:Test,代码行数:29,代码来源:Form1.cs

示例11: SignalRProxySingleton

        public SignalRProxySingleton()
        {
            conn = new HubConnection(ConfigurationManager.AppSettings["SignalRURL"]);
            homeHub = conn.CreateHubProxy(ConfigurationManager.AppSettings["HubName"]);

            conn.Start().GetAwaiter().GetResult();
        }
开发者ID:vincomi,项目名称:OSm,代码行数:7,代码来源:SignalRProxySingleton.cs

示例12: CustomerUpdateNotifier

        internal CustomerUpdateNotifier()
        {
            var hubConnection = new HubConnection(AppSettings.CustomerUpdateHubUrl);
            _hubProxy = hubConnection.CreateHubProxy(AppSettings.CustomerUpdateHubName);

            hubConnection.Start().Wait();
        }
开发者ID:EdsonF,项目名称:SignalRse,代码行数:7,代码来源:CustomerUpdateNotifier.cs

示例13: Main

        static void Main()
        {
            Console.WriteLine("Creating hub");
            using (var hubConnection = new HubConnection("http://localhost:1906/"))
            {
                var eventHubProxy = hubConnection.CreateHubProxy("EventHub");
                eventHubProxy.On<Message>("Receive", message => OnReceive(message));
                //eventHubProxy.On<Message>("UpdateConfiguration", message => OnUpdateConfiguration(message));
                hubConnection.Start().Wait();
                //eventHubProxy.Invoke<Message>("RequestConfiguration").Wait();

                Console.WriteLine("Hub created");
                while (true)
                {
                    Console.Write("Values: ");
                    var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(Console.ReadLine());
                    var message = new Message
                    {
                        Sender = typeof(Program).FullName,
                        Target = "ArtNet",
                        Time = DateTime.Now,
                        Values = values
                    };
                    Console.WriteLine("Sending message");
                    eventHubProxy.Invoke<Message>("Send", message).Wait();
                    Console.WriteLine("Message sent");
                }
            }
        }
开发者ID:wertzui,项目名称:HomeController,代码行数:29,代码来源:Program.cs

示例14: ConnectAsync

        private async void ConnectAsync()
        {
            con = new HubConnection(ServerURI);
            con.Closed += Connection_Closed;
            con.Error += Connection_Error;
            HubProxy = con.CreateHubProxy("MyHub");
            //Handle incoming event from server: use Invoke to write to console from SignalR's thread
            HubProxy.On<string>("getPos", (message) =>
                Dispatcher.BeginInvoke(() => test(message))
            );
            try
            {
                await con.Start();
            }
            catch (HttpRequestException)
            {
                //No connection: Don't enable Send button or show chat UI
                btntrack.Content  = "eror";
            }
            catch (HttpClientException)
            {
                btntrack.Content = "eror";
            }

            Dispatcher.BeginInvoke(() =>
            {
                HubProxy.Invoke("Connect", "15");
            });
        }
开发者ID:kleitz,项目名称:WPApp,代码行数:29,代码来源:Tracking.xaml.cs

示例15: CrestLogger

 public CrestLogger()
 {
     var hubConnection = new HubConnection("http://www.contoso.com/");
     errorLogHubProxy = hubConnection.CreateHubProxy("ErrorLogHub");
     //errorLogHubProxy.On<Error>("LogError", error => { });
     hubConnection.Start().Wait();
 }
开发者ID:calvaryccm,项目名称:Crest,代码行数:7,代码来源:CrestLogger.cs


注:本文中的Microsoft.AspNet.SignalR.Client.HubConnection.Start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。