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


C# Client.Connection.SendWithTimeout方法代码示例

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


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

示例1: GroupsReceiveMessages

            public void GroupsReceiveMessages(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize();

                    var connection = new Client.Connection(host.Url + "/groups");
                    var list = new List<string>();
                    connection.Received += data =>
                    {
                        list.Add(data);
                    };

                    connection.Start(host.Transport).Wait();

                    // Join the group
                    connection.SendWithTimeout(new { type = 1, group = "test" });

                    // Sent a message
                    connection.SendWithTimeout(new { type = 3, group = "test", message = "hello to group test" });

                    // Leave the group
                    connection.SendWithTimeout(new { type = 2, group = "test" });

                    // Send a message
                    connection.SendWithTimeout(new { type = 3, group = "test", message = "goodbye to group test" });

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    connection.Stop();

                    Assert.Equal(1, list.Count);
                    Assert.Equal("hello to group test", list[0]);
                }
            }
开发者ID:elylucas,项目名称:SignalR,代码行数:35,代码来源:PersistentConnectionFacts.cs

示例2: ClientGroupsSyncWithServerGroupsOnReconnect

            public void ClientGroupsSyncWithServerGroupsOnReconnect(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize(keepAlive: 0,
                                    connectionTimeout: 5,
                                    hearbeatInterval: 2);

                    var connection = new Client.Connection(host.Url + "/rejoin-groups");
                    var inGroupOnReconnect = new List<bool>();
                    var wh = new ManualResetEventSlim();

                    connection.Received += message =>
                    {
                        Assert.Equal("Reconnected", message);
                        wh.Set();
                    };

                    connection.Reconnected += () =>
                    {
                        inGroupOnReconnect.Add(connection.Groups.Contains(typeof(MyRejoinGroupsConnection).FullName + ".test"));

                        connection.SendWithTimeout(new { type = 3, group = "test", message = "Reconnected" });
                    };

                    connection.Start(host.Transport).Wait();

                    // Join the group
                    connection.SendWithTimeout(new { type = 1, group = "test" });

                    // Force reconnect
                    Thread.Sleep(TimeSpan.FromSeconds(10));

                    Assert.True(wh.Wait(TimeSpan.FromSeconds(5)), "Client didn't receive message sent to test group.");
                    Assert.True(inGroupOnReconnect.Count > 0);
                    Assert.True(inGroupOnReconnect.All(b => b));

                    connection.Stop();
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:40,代码来源:PersistentConnectionFacts.cs

示例3: SendWithSyncErrorThrows

            public void SendWithSyncErrorThrows(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize();

                    var connection = new Client.Connection(host.Url + "/sync-error");

                    connection.Start(host.Transport).Wait();

                    Assert.Throws<AggregateException>(() => connection.SendWithTimeout("test"));

                    connection.Stop();
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:15,代码来源:PersistentConnectionFacts.cs

示例4: SendToAllButCaller

            public void SendToAllButCaller(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize();

                    var connection1 = new Client.Connection(host.Url + "/filter");
                    var connection2 = new Client.Connection(host.Url + "/filter");

                    var wh1 = new ManualResetEventSlim(initialState: false);
                    var wh2 = new ManualResetEventSlim(initialState: false);

                    connection1.Received += data => wh1.Set();
                    connection2.Received += data => wh2.Set();

                    connection1.Start(host.Transport).Wait();
                    connection2.Start(host.Transport).Wait();

                    connection1.SendWithTimeout("test");

                    Assert.False(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
                    Assert.True(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));

                    connection1.Stop();
                    connection2.Stop();
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:27,代码来源:PersistentConnectionFacts.cs

示例5: EnvironmentIsAvailable

            public void EnvironmentIsAvailable(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize();

                    var connection = new Client.Connection(host.Url + "/items");
                    var connection2 = new Client.Connection(host.Url + "/items");

                    var results = new List<RequestItemsResponse>();
                    connection2.Received += data =>
                    {
                        var val = JsonConvert.DeserializeObject<RequestItemsResponse>(data);
                        if (!results.Contains(val))
                        {
                            results.Add(val);
                        }
                    };

                    connection.Start(host.Transport).Wait();
                    connection2.Start(host.Transport).Wait();

                    Thread.Sleep(TimeSpan.FromSeconds(2));

                    connection.SendWithTimeout(null);

                    Thread.Sleep(TimeSpan.FromSeconds(2));

                    connection.Stop();

                    Thread.Sleep(TimeSpan.FromSeconds(2));

                    Debug.WriteLine(String.Join(", ", results));

                    Assert.Equal(3, results.Count);
                    Assert.Equal("OnConnectedAsync", results[0].Method);
                    Assert.Equal(1, results[0].Keys.Length);
                    Assert.Equal("owin.environment", results[0].Keys[0]);
                    Assert.Equal("OnReceivedAsync", results[1].Method);
                    Assert.Equal(1, results[1].Keys.Length);
                    Assert.Equal("owin.environment", results[1].Keys[0]);
                    Assert.Equal("OnDisconnectAsync", results[2].Method);
                    Assert.Equal(1, results[2].Keys.Length);
                    Assert.Equal("owin.environment", results[2].Keys[0]);

                    connection2.Stop();
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:48,代码来源:PersistentConnectionFacts.cs

示例6: SendRaisesOnReceivedFromAllEvents

            public void SendRaisesOnReceivedFromAllEvents(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize();

                    var connection = new Client.Connection(host.Url + "/multisend");
                    var results = new List<string>();
                    connection.Received += data =>
                    {
                        results.Add(data);
                    };

                    connection.Start(host.Transport).Wait();
                    connection.SendWithTimeout("");

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    connection.Stop();

                    Debug.WriteLine(String.Join(", ", results));

                    Assert.Equal(4, results.Count);
                    Assert.Equal("OnConnectedAsync1", results[0]);
                    Assert.Equal("OnConnectedAsync2", results[1]);
                    Assert.Equal("OnReceivedAsync1", results[2]);
                    Assert.Equal("OnReceivedAsync2", results[3]);
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:29,代码来源:PersistentConnectionFacts.cs

示例7: SendCanBeCalledAfterStateChangedEvent

            public void SendCanBeCalledAfterStateChangedEvent(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize();

                    var connection = new Client.Connection(host.Url + "/multisend");
                    var results = new List<string>();
                    connection.Received += data =>
                    {
                        results.Add(data);
                    };

                    connection.StateChanged += stateChange =>
                    {
                        if (stateChange.NewState == Client.ConnectionState.Connected)
                        {
                            connection.SendWithTimeout("");
                        }
                    };

                    connection.Start(host.Transport).Wait();

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    connection.Stop();

                    Debug.WriteLine(String.Join(", ", results));

                    Assert.Equal(4, results.Count);
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:32,代码来源:PersistentConnectionFacts.cs

示例8: GroupCanBeAddedAndMessagedOnConnected

            public void GroupCanBeAddedAndMessagedOnConnected(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    var wh = new ManualResetEventSlim();
                    host.Initialize();

                    var connection = new Client.Connection(host.Url + "/add-group");
                    connection.Received += data =>
                    {
                        Assert.Equal("hey", data);
                        wh.Set();
                    };

                    connection.Start(host.Transport).Wait();
                    connection.SendWithTimeout("");

                    Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));

                    connection.Stop();
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:22,代码来源:PersistentConnectionFacts.cs

示例9: GroupsRejoinedWhenOnRejoiningGroupsOverridden

            public void GroupsRejoinedWhenOnRejoiningGroupsOverridden(HostType hostType, TransportType transportType)
            {
                using (var host = CreateHost(hostType, transportType))
                {
                    host.Initialize(keepAlive: 0,
                                    connectionTimeout: 2,
                                    hearbeatInterval: 2);

                    var connection = new Client.Connection(host.Url + "/rejoin-groups");

                    var list = new List<string>();
                    connection.Received += data =>
                    {
                        list.Add(data);
                    };

                    connection.Start(host.Transport).Wait();

                    // Join the group
                    connection.SendWithTimeout(new { type = 1, group = "test" });

                    // Sent a message
                    connection.SendWithTimeout(new { type = 3, group = "test", message = "hello to group test" });

                    // Force Reconnect
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    // Send a message
                    connection.SendWithTimeout(new { type = 3, group = "test", message = "goodbye to group test" });

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    connection.Stop();

                    Assert.Equal(2, list.Count);
                    Assert.Equal("hello to group test", list[0]);
                    Assert.Equal("goodbye to group test", list[1]);
                }
            }
开发者ID:Jozef89,项目名称:SignalR,代码行数:39,代码来源:PersistentConnectionFacts.cs

示例10: ConnectionIdsCantBeUsedAsGroups

        public void ConnectionIdsCantBeUsedAsGroups()
        {
            using (var host = new MemoryHost())
            {
                IProtectedData protectedData = null;

                host.Configure(app =>
                {
                    var config = new ConnectionConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    app.MapSignalR<MyConnection>("/echo", config);

                    protectedData = config.Resolver.Resolve<IProtectedData>();
                });

                var connection = new Client.Connection("http://memoryhost/echo");

                using (connection)
                {
                    var connectionTcs = new TaskCompletionSource<string>();
                    var spyTcs = new TaskCompletionSource<string>();

                    connection.Received += data =>
                    {
                        connectionTcs.SetResult(data.Trim());
                    };

                    connection.Start(host).Wait();

                    var tcs = new TaskCompletionSource<object>();
                    EventSourceStreamReader reader = null;

                    Task.Run(async () =>
                    {
                        try
                        {
                            string url = GetUrl(protectedData, connection);
                            var response = await host.Get(url, r => { }, isLongRunning: true);
                            reader = new EventSourceStreamReader(connection, response.GetStream());

                            reader.Message = sseEvent =>
                            {
                                if (sseEvent.EventType == EventType.Data &&
                                    sseEvent.Data != "initialized" &&
                                    sseEvent.Data != "{}")
                                {
                                    spyTcs.TrySetResult(sseEvent.Data);
                                }
                            };

                            reader.Start();
                            tcs.TrySetResult(null);
                        }
                        catch (Exception ex)
                        {
                            tcs.TrySetException(ex);
                        }
                    });

                    tcs.Task.Wait();

                    connection.SendWithTimeout("STUFFF");

                    Assert.True(connectionTcs.Task.Wait(TimeSpan.FromSeconds(5)));
                    Assert.Equal("STUFFF", connectionTcs.Task.Result);
                    Assert.False(spyTcs.Task.Wait(TimeSpan.FromSeconds(5)));
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:72,代码来源:SecurityFacts.cs


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