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


C# Connection.Start方法代码示例

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


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

示例1: SendingBigData

            public void SendingBigData()
            {
                var host = new MemoryHost();
                host.MapConnection<SampleConnection>("/echo");

                var connection = new Connection("http://foo/echo");

                var wh = new ManualResetEventSlim();
                var n = 0;
                var target = 20;

                connection.Received += data =>
                {
                    n++;
                    if (n == target)
                    {
                        wh.Set();
                    }
                };

                connection.Start(host).Wait();

                var conn = host.ConnectionManager.GetConnection<SampleConnection>();

                for (int i = 0; i < target; ++i)
                {
                    var node = new BigData();
                    conn.Broadcast(node).Wait();
                    Thread.Sleep(1000);
                }

                Assert.True(wh.Wait(TimeSpan.FromMinutes(1)), "Timed out");
            }
开发者ID:rhoadsce,项目名称:SignalR,代码行数:33,代码来源:ConnectionFacts.cs

示例2: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var messageListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, new List<string>());
            var messageList = FindViewById<ListView>(Resource.Id.Messages);
            messageList.Adapter = messageListAdapter;

            var connection = new Connection("http://10.0.2.2:8081/echo");
            connection.Received += data =>
                RunOnUiThread(() => messageListAdapter.Add(data));

            var sendMessage = FindViewById<Button>(Resource.Id.SendMessage);
            var message = FindViewById<TextView>(Resource.Id.Message);

            sendMessage.Click += delegate
            {
                if (!string.IsNullOrWhiteSpace(message.Text) && connection.State == ConnectionState.Connected)
                {
                    connection.Send("Android: " + message.Text);

                    RunOnUiThread(() => message.Text = "");
                }
            };

            connection.Start().ContinueWith(task => connection.Send("Android: connected"));
        }
开发者ID:cryophobia,项目名称:SignalR,代码行数:29,代码来源:DemoActivity.cs

示例3: RunStreamingSample

        private static void RunStreamingSample()
        {
            var connection = new Connection("http://localhost:40476/Raw/raw");

            connection.Received += data =>
            {
                Console.WriteLine(data);
            };

            connection.Reconnected += () =>
            {
                Console.WriteLine("[{0}]: Connection restablished", DateTime.Now);
            };

            connection.Error += e =>
            {
                Console.WriteLine(e);
            };

            connection.Start().Wait();

            string line = null;
            while ((line = Console.ReadLine()) != null)
            {
                connection.Send(new { type = 1, value = line });
            }
        }
开发者ID:RodH257,项目名称:SignalR,代码行数:27,代码来源:Program.cs

示例4: RunInMemoryHost

        private static void RunInMemoryHost()
        {
            var host = new MemoryHost();
            host.MapConnection<MyConnection>("/echo");

            var connection = new Connection("http://foo/echo");

            connection.Received += data =>
            {
                Console.WriteLine(data);
            };

            connection.Start(host).Wait();

            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    while (true)
                    {
                        connection.Send(DateTime.Now.ToString());

                        Thread.Sleep(2000);
                    }
                }
                catch
                {

                }
            });
        }
开发者ID:ninjaAB,项目名称:SignalR,代码行数:31,代码来源:Program.cs

示例5: MainPage

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            var connection = new Connection("http://localhost:40476/Raw/raw");
            connection.Received += data =>
            {
                App.ViewModel.Items.Add(new ItemViewModel { LineOne = data });
            };

            connection.Error += ex =>
            {
                var aggEx = (AggregateException)ex;
                App.ViewModel.Items.Add(new ItemViewModel { LineOne = aggEx.InnerExceptions[0].Message });
            };

            connection.Reconnected += () =>
            {
                App.ViewModel.Items.Add(new ItemViewModel { LineOne = "Connection restored" });
            };

            var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
            connection.Start().ContinueWith(task =>
            {
                var ex = task.Exception.InnerExceptions[0];
                App.ViewModel.Items.Add(new ItemViewModel { LineOne = ex.Message });
            },
            CancellationToken.None,
            TaskContinuationOptions.OnlyOnFaulted,
            scheduler);
        }
开发者ID:4engkai,项目名称:SignalR,代码行数:36,代码来源:MainPage.xaml.cs

示例6: RunStreaming

        private async Task RunStreaming()
        {
            string url = "http://signalr01.cloudapp.net/streaming-connection";

            var connection = new Connection(url);
            connection.TraceWriter = _traceWriter;

            await connection.Start();
            connection.TraceWriter.WriteLine("transport.Name={0}", connection.Transport.Name);
        }
开发者ID:selzero,项目名称:SignalR-Clients,代码行数:10,代码来源:CommonClient.cs

示例7: Main

		public static void Main (string[] args)
		{
			// create a connection object and pass it the url to connect to
			Connection conn = new Connection(ServerURL);
			// subscribe to the connection state chenged event
			conn.StateChanged += Connection_StateChanged;
			// start the connection
			conn.Start ();

			// keep the console live
			Console.ReadLine ();
		}
开发者ID:BanxCapital,项目名称:Banx.io-WSSR-API-MONO-Examples,代码行数:12,代码来源:Program.cs

示例8: FailedNegotiateShouldNotBeActive

            public void FailedNegotiateShouldNotBeActive()
            {
                var connection = new Connection("http://test");
                var transport = new Mock<IClientTransport>();
                transport.Setup(m => m.Negotiate(connection))
                         .Returns(TaskAsyncHelper.FromError<NegotiationResponse>(new InvalidOperationException("Something failed.")));

                var aggEx = Assert.Throws<AggregateException>(() => connection.Start(transport.Object).Wait());
                var ex = aggEx.Unwrap();
                Assert.IsType(typeof(InvalidOperationException), ex);
                Assert.Equal("Something failed.", ex.Message);
                Assert.Equal(ConnectionState.Disconnected, connection.State);
            }
开发者ID:rmarinho,项目名称:SignalR,代码行数:13,代码来源:ConnectionFacts.cs

示例9: RunRawConnection

        private async Task RunRawConnection()
        {
            string url = "http://signalr01.cloudapp.net/raw-connection";

            var connection = new Connection(url);
            connection.TraceWriter = _traceWriter;

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

            await connection.Send(new { type = 1, value = "first message" });
            await connection.Send(new { type = 1, value = "second message" });
        }
开发者ID:selzero,项目名称:SignalR-Clients,代码行数:13,代码来源:CommonClient.cs

示例10: Main

        static void Main(string[] args)
        {
            var connection = new Connection("http://localhost:2329/Home/echo");
            connection.Received += data =>
                {
                    Console.WriteLine(data);
                };

            connection.Start().Wait();
            connection.Send("Testing from C# Console App");

            Console.ReadLine();
        }
开发者ID:denmerc,项目名称:SignalR.Demo,代码行数:13,代码来源:Program.cs

示例11: FailsIfProtocolVersionIsNull

            public void FailsIfProtocolVersionIsNull()
            {
                var connection = new Connection("http://test");
                var transport = new Mock<IClientTransport>();
                transport.Setup(m => m.Negotiate(connection)).Returns(TaskAsyncHelper.FromResult(new NegotiationResponse
                {
                    ProtocolVersion = null
                }));

                var aggEx = Assert.Throws<AggregateException>(() => connection.Start(transport.Object).Wait());
                var ex = aggEx.Unwrap();
                Assert.IsType(typeof(InvalidOperationException), ex);
                Assert.Equal("Incompatible protocol version.", ex.Message);
            }
开发者ID:rmarinho,项目名称:SignalR,代码行数:14,代码来源:ConnectionFacts.cs

示例12: RemoteCommandExecutor

        public RemoteCommandExecutor(string serviceUrl)
        {
            serviceUrl = UrlUtility.EnsureTrailingSlash(serviceUrl);
            _client = HttpClientHelper.Create(serviceUrl);

            _connection = new Connection(serviceUrl + "status");
            _connection.Received += data => {
                if (CommandEvent != null) {
                    var commandEvent = JsonConvert.DeserializeObject<CommandEvent>(data);
                    CommandEvent(commandEvent);
                }
            };

            _connection.Start();
        }
开发者ID:RaleighHokie,项目名称:kudu,代码行数:15,代码来源:RemoteCommandExecutor.cs

示例13: RunStreamingSample

        private static void RunStreamingSample()
        {
            var connection = new Connection("http://localhost:40476/Streaming/streaming");

            connection.Received += data =>
            {
                Console.WriteLine(data);
            };

            connection.Error += e =>
            {
                Console.WriteLine(e);
            };

            connection.Start().Wait();
        }
开发者ID:niik,项目名称:SignalR,代码行数:16,代码来源:Program.cs

示例14: RemoteDeploymentManager

        public RemoteDeploymentManager(string serviceUrl)
        {
            serviceUrl = UrlUtility.EnsureTrailingSlash(serviceUrl);
            _client = HttpClientHelper.Create(serviceUrl);

            // Raise the event when data comes in
            var connection = new Connection(serviceUrl + "status");
            connection.Received += data => {
                if (StatusChanged != null) {
                    var result = JsonConvert.DeserializeObject<DeployResult>(data);
                    StatusChanged(result);
                }
            };

            connection.Start();
        }
开发者ID:nulltoken,项目名称:kudu,代码行数:16,代码来源:RemoteDeploymentManager.cs

示例15: signalr_connection_is_alive

        public void signalr_connection_is_alive()
        {
            this._autoResetEvent = new AutoResetEvent(false);

            var connection = new Connection("http://localhost:2329/echo");
            connection.Received += data =>
            {
                this._autoResetEvent.Set();
                Console.WriteLine(data);
                Assert.Pass();
            };

            connection.Start().Wait();
            connection.Send("Testing from C# Console App");
            this._autoResetEvent.WaitOne();
        }
开发者ID:denmerc,项目名称:SignalR.Demo,代码行数:16,代码来源:ConnectionTests.cs


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