Exemple #1
0
        static async Task Main(string[] args)
        {
            Console.Title = "client";
            var client_bootstrap = TcpFactory.ClientBootstrap();

            client_bootstrap.ConfigurationGlobalOptions(options => { });
            client_bootstrap.ConfigurationGlobalFilter((pipeline) =>
            {
                var filter = new TcpClientFilter();
                _clientFilters.Add(filter);

                pipeline.Add(new DefaultFixedHeaderBytesFilter());
                pipeline.Add(filter);
            });

            if (SocketConfig.useSsl)
            {
                client_bootstrap.ConfigurationSsl(new SslClientOptions(SocketConfig.cert.GetNameInfo(X509NameType.DnsName, false)), stream =>
                {
                    return(new SslStream(stream, true, (sender, certificate, chain, sslPolicyErrors) => true));
                });
            }
            await client_bootstrap.BuildAsync();


            for (int i = 0; i < 5000; i++)
            {
                var c_channel = await client_bootstrap.CreateChannelAsync();

                await c_channel.StartAsync(address);
            }

            System.Threading.Thread.Sleep(3 * 1000);
            Console.WriteLine("start send");

            startTime = DateTime.Now;
            startSend();

            while (true)
            {
                string str = Console.ReadLine();
                if (str == "c")
                {
                    return;
                }

                if (str == "t")
                {
                    var  totalSeconds = (DateTime.Now - startTime).TotalSeconds;
                    long count        = 0;
                    foreach (var filter in _clientFilters)
                    {
                        count += filter.count;
                    }

                    Console.WriteLine("平均每秒:" + count / totalSeconds);
                }
            }
        }
Exemple #2
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureServices((hostContext, services) =>
 {
     services.AddHostedService <ServerWorker>();
     services.AddSingleton <INotification, ConsoleNotification>();
     services.AddSingleton <IResponseStrategyFactory, ResponseStrategyFactory>();
     services.AddSingleton(TcpFactory.CreateListener());
     services.AddSingleton <IConnectionListener, AppTcpListener>();
 });
Exemple #3
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureServices((hostContext, services) =>
 {
     services.AddHostedService <ClientWorker>();
     services.AddSingleton <INotification, ConsoleNotification>();
     services.AddSingleton(TcpFactory.CreateClient());
     services.AddSingleton <IConnectionClient, AppTcpClient>();
     services.AddSingleton <IClient, ClientModel>();
     services.AddSingleton <IRequestFactory, RequestFactory>();
     services.AddSingleton <IResponseMessageFactory, ResponseMessageFactory>();
 });
Exemple #4
0
        static async Task Main(string[] args)
        {
            Console.Title = "server";

            ITcpServerBootstrap server_bootstrap = TcpFactory.ServerBootstrap();

            server_bootstrap.ConfigurationGlobalOptions(options => { });
            server_bootstrap.ConfigurationGlobalFilter((pipeline) =>
            {
                pipeline.Add(new DefaultFixedHeaderBytesFilter());
                pipeline.Add(new TcpServerFilter());
            });

            if (common.SocketConfig.useSsl)
            {
                server_bootstrap.ConfigurationSsl(new SslServerOptions(common.SocketConfig.cert, false, false), stream =>
                {
                    return(new SslStream(stream, true, (sender, certificate, chain, sslPolicyErrors) => true));
                });
            }
            await server_bootstrap.BuildAsync();

            var s_channel = await server_bootstrap.CreateChannelAsync();

            await s_channel.StartAsync(address);


            while (true)
            {
                string str = Console.ReadLine();
                if (str == "c")
                {
                    return;
                }

                if (str == "t")
                {
                    Console.WriteLine("当前客户端连接数量:" + ServerStatistics.client_count);
                }
            }
        }
Exemple #5
0
        static async Task Main(string[] args)
        {
            var server_bootstrap = TcpFactory.ServerBootstrap();

            server_bootstrap.ConfigurationGlobalOptions(options =>
            {
            });

            server_bootstrap.ConfigurationGlobalFilter((pipeline) =>
            {
                pipeline.Add(new DefaultFixedHeaderBytesFilter());
                pipeline.Add(new TcpTestFilter_Server());
            });

            if (isUseSsl)
            {
                server_bootstrap.ConfigurationSsl(new SslServerOptions(cert, false, false),
                                                  stream =>
                {
                    return(new SslStream(stream, true, (sender, certificate, chain, sslPolicyErrors) => true));
                });
            }

            await server_bootstrap.BuildAsync();

            var client_bootstrap = TcpFactory.ClientBootstrap();

            client_bootstrap.ConfigurationGlobalOptions((options =>
            {
            }));

            client_bootstrap.ConfigurationGlobalFilter((pipeline) =>
            {
                pipeline.Add(new DefaultFixedHeaderBytesFilter());
                pipeline.Add(new TcpTestFilter_Client());
            });

            if (isUseSsl)
            {
                client_bootstrap.ConfigurationSsl(new SslClientOptions(cert.GetNameInfo(X509NameType.DnsName, false)),
                                                  stream =>
                {
                    return(new SslStream(stream, true, (sender, certificate, chain, sslPolicyErrors) => true));
                }
                                                  );
            }

            await client_bootstrap.BuildAsync();

            var s_channel = await server_bootstrap.CreateChannelAsync();

            await s_channel.StartAsync(address);

            var c_channel = await client_bootstrap.CreateChannelAsync();

            await c_channel.StartAsync(address);


            int count = 0;

            while (true)
            {
                string str = Console.ReadLine();
                if (str == "send")
                {
                    count++;
                    for (int i = 1; i <= 100; i++)
                    {
                        for (int j = 1; j <= 5; j++)
                        {
                            string com   = $"{count}____{i}______{j}";
                            var    bytes = System.Text.Encoding.UTF8.GetBytes(com);
                            M.session.Write(bytes);
                        }

                        await M.session.FlushAsync();
                    }
                }
                else if (str == "c")
                {
                    await M.session.CloseAsync();
                }
                else if (str == "s")
                {
                    return;
                }
            }
        }
Exemple #6
0
 private void button10_Click(object sender, EventArgs e)
 {
     TcpFactory.Show();
 }