Exemplo n.º 1
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            Task.Run(async() =>
            {
                try
                {
                    var config = new AsyncWebSocketClientConfiguration();
                    //config.SslTargetHost = "Cowboy";
                    //config.SslClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.cer"));
                    //config.SslPolicyErrorsBypassed = true;

                    //var uri = new Uri("ws://echo.websocket.org/");
                    //var uri = new Uri("wss://127.0.0.1:22222/test");
                    var uri = new Uri("ws://127.0.0.1:22222/test");
                    _client = new AsyncWebSocketClient(uri,
                                                       OnServerTextReceived,
                                                       OnServerBinaryReceived,
                                                       OnServerConnected,
                                                       OnServerDisconnected,
                                                       config);
                    await _client.Connect();

                    Console.WriteLine("WebSocket client has connected to server [{0}].", uri);
                    Console.WriteLine("Type something to send to server...");
                    while (_client.State == WebSocketState.Open)
                    {
                        try
                        {
                            string text = Console.ReadLine();
                            if (text == "quit")
                            {
                                break;
                            }
                            Task.Run(async() =>
                            {
                                if (text == "many")
                                {
                                    text            = new string('x', 1024);
                                    Stopwatch watch = Stopwatch.StartNew();
                                    int count       = 10000;
                                    for (int i = 1; i <= count; i++)
                                    {
                                        await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                        Console.WriteLine("Client [{0}] send binary -> Sequence[{1}] -> TextLength[{2}].",
                                                          _client.LocalEndPoint, i, text.Length);
                                    }
                                    watch.Stop();
                                    Console.WriteLine("Client [{0}] send binary -> Count[{1}] -> Cost[{2}] -> PerSecond[{3}].",
                                                      _client.LocalEndPoint, count, watch.ElapsedMilliseconds / 1000, count / (watch.ElapsedMilliseconds / 1000));
                                }
                                else if (text == "big")
                                {
                                    text = new string('x', 1024 * 1024 * 100);
                                    await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send binary -> [{1}].", _client.LocalEndPoint, text);
                                }
                                else if (text == "8192")
                                {
                                    text = new string('x', 1024 * 8);
                                    await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send binary -> [{1}].", _client.LocalEndPoint, text);
                                }
                                else if (text == "4096")
                                {
                                    text = new string('x', 1024 * 4);
                                    await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send binary -> [{1}].", _client.LocalEndPoint, text);
                                }
                                else if (text == "2048")
                                {
                                    text = new string('x', 1024 * 2);
                                    await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send binary -> [{1}].", _client.LocalEndPoint, text);
                                }
                                else if (text == "1024")
                                {
                                    text = new string('x', 1024);
                                    await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send binary -> [{1}].", _client.LocalEndPoint, text);
                                }
                                else
                                {
                                    await _client.SendBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send binary -> [{1}].", _client.LocalEndPoint, text);

                                    //await _client.SendTextAsync(text);
                                    //Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text);
                                }
                            }).Forget();
                        }
                        catch (Exception ex)
                        {
                            Logger.Get <Program>().Error(ex.Message, ex);
                        }
                    }

                    await _client.Close(WebSocketCloseCode.NormalClosure);
                    Console.WriteLine("WebSocket client has disconnected from server [{0}].", uri);
                }
                catch (Exception ex)
                {
                    Logger.Get <Program>().Error(ex.Message, ex);
                }
            }).Wait();

            Console.ReadKey();
        }
Exemplo n.º 2
0
 static Program()
 {
     NLogLogger.Use();
     _log = Logger.Get <Program>();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            try
            {
                var config = new TcpSocketSaeaServerConfiguration();

                //config.FrameBuilder = new FixedLengthFrameBuilder(20000);
                //config.FrameBuilder = new RawBufferFrameBuilder();
                //config.FrameBuilder = new LineBasedFrameBuilder();
                //config.FrameBuilder = new LengthPrefixedFrameBuilder();
                //config.FrameBuilder = new LengthFieldBasedFrameBuilder();

                _server = new TcpSocketSaeaServer(22222, new SimpleMessageDispatcher(), config);
                _server.Listen();

                Console.WriteLine("TCP server has been started on [{0}].", _server.ListenedEndPoint);
                Console.WriteLine("Type something to send to clients...");
                while (true)
                {
                    try
                    {
                        string text = Console.ReadLine();
                        if (text == "quit")
                        {
                            break;
                        }
                        Task.Run(async() =>
                        {
                            if (text == "many")
                            {
                                text = new string('x', 8192);
                                for (int i = 0; i < 1000000; i++)
                                {
                                    await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Server [{0}] broadcasts text -> [{1}].", _server.ListenedEndPoint, text);
                                }
                            }
                            else if (text == "big1")
                            {
                                text = new string('x', 1024 * 1024 * 1);
                                await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Server [{0}] broadcasts text -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else if (text == "big10")
                            {
                                text = new string('x', 1024 * 1024 * 10);
                                await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Server [{0}] broadcasts text -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else if (text == "big100")
                            {
                                text = new string('x', 1024 * 1024 * 100);
                                await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Server [{0}] broadcasts text -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else if (text == "big1000")
                            {
                                text = new string('x', 1024 * 1024 * 1000);
                                await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Server [{0}] broadcasts text -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else
                            {
                                await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Server [{0}] broadcasts text -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.Get <Program>().Error(ex.Message, ex);
                    }
                }

                _server.Shutdown();
                Console.WriteLine("TCP server has been stopped on [{0}].", _server.ListenedEndPoint);
            }
            catch (Exception ex)
            {
                Logger.Get <Program>().Error(ex.Message, ex);
            }

            Console.ReadKey();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            ILog log = Logger.Get <Program>();

            var actor = new RpcActor();

            var helloClient = new HelloClient(actor);
            var calcClient  = new CalcClient(actor);
            var orderClient = new OrderClient(actor);

            actor.RegisterRpcService(helloClient);
            actor.RegisterRpcService(calcClient);
            actor.RegisterRpcService(orderClient);

            actor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        actor.Shutdown();
                        actor.Bootup();
                    }
                    else if (text == "hello")
                    {
                        Hello(log, helloClient);
                    }
                    else if (text == "hello10000")
                    {
                        Hello10000(log, helloClient);
                    }
                    #region hello10000
                    else if (text == "hello10000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 1);
                    }
                    else if (text == "hello10000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 2);
                    }
                    else if (text == "hello10000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 4);
                    }
                    else if (text == "hello10000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 8);
                    }
                    else if (text == "hello10000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 16);
                    }
                    else if (text == "hello10000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 10000, 32);
                    }
                    #endregion
                    #region hello20000
                    else if (text == "hello20000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 1);
                    }
                    else if (text == "hello20000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 2);
                    }
                    else if (text == "hello20000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 4);
                    }
                    else if (text == "hello20000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 8);
                    }
                    else if (text == "hello20000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 16);
                    }
                    else if (text == "hello20000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 20000, 32);
                    }
                    #endregion
                    #region hello100000
                    else if (text == "hello100000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 1);
                    }
                    else if (text == "hello100000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 2);
                    }
                    else if (text == "hello100000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 4);
                    }
                    else if (text == "hello100000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 8);
                    }
                    else if (text == "hello100000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 16);
                    }
                    else if (text == "hello100000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 100000, 32);
                    }
                    #endregion
                    #region hello300000
                    else if (text == "hello300000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 1);
                    }
                    else if (text == "hello300000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 2);
                    }
                    else if (text == "hello300000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 4);
                    }
                    else if (text == "hello300000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 8);
                    }
                    else if (text == "hello300000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 16);
                    }
                    else if (text == "hello300000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 300000, 32);
                    }
                    #endregion
                    #region hello1500000
                    else if (text == "hello1500000x1")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 1);
                    }
                    else if (text == "hello1500000x2")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 2);
                    }
                    else if (text == "hello1500000x4")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 4);
                    }
                    else if (text == "hello1500000x8")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 8);
                    }
                    else if (text == "hello1500000x16")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 16);
                    }
                    else if (text == "hello1500000x32")
                    {
                        Hello10000MultiThreading(log, helloClient, 1500000, 32);
                    }
                    #endregion
                    #region add10000
                    else if (text == "add10000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 1);
                    }
                    else if (text == "add10000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 2);
                    }
                    else if (text == "add10000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 4);
                    }
                    else if (text == "add10000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 8);
                    }
                    else if (text == "add10000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 16);
                    }
                    else if (text == "add10000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 10000, 32);
                    }
                    #endregion
                    #region add20000
                    else if (text == "add20000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 1);
                    }
                    else if (text == "add20000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 2);
                    }
                    else if (text == "add20000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 4);
                    }
                    else if (text == "add20000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 8);
                    }
                    else if (text == "add20000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 16);
                    }
                    else if (text == "add20000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 20000, 32);
                    }
                    #endregion
                    #region add100000
                    else if (text == "add100000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 1);
                    }
                    else if (text == "add100000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 2);
                    }
                    else if (text == "add100000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 4);
                    }
                    else if (text == "add100000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 8);
                    }
                    else if (text == "add100000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 16);
                    }
                    else if (text == "add100000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 100000, 32);
                    }
                    #endregion
                    #region add300000
                    else if (text == "add300000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 1);
                    }
                    else if (text == "add300000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 2);
                    }
                    else if (text == "add300000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 4);
                    }
                    else if (text == "add300000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 8);
                    }
                    else if (text == "add300000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 16);
                    }
                    else if (text == "add300000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 300000, 32);
                    }
                    #endregion
                    #region add1500000
                    else if (text == "add1500000x1")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 1);
                    }
                    else if (text == "add1500000x2")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 2);
                    }
                    else if (text == "add1500000x4")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 4);
                    }
                    else if (text == "add1500000x8")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 8);
                    }
                    else if (text == "add1500000x16")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 16);
                    }
                    else if (text == "add1500000x32")
                    {
                        Add10000MultiThreading(log, calcClient, 1500000, 32);
                    }
                    #endregion
                    else
                    {
                        int times = 0;
                        if (int.TryParse(text, out times))
                        {
                            for (int i = 0; i < times; i++)
                            {
                                PlaceOrder(log, orderClient);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            actor.Shutdown();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            ConnectToServer();

            Console.WriteLine("TCP client has connected to server.");
            Console.WriteLine("Type something to send to server...");
            while (true)
            {
                try
                {
                    string text = Console.ReadLine();
                    if (text == "quit")
                    {
                        break;
                    }
                    else if (text == "many")
                    {
                        text = new string('x', 8192);
                        for (int i = 0; i < 1000000; i++)
                        {
                            _client.Send(Encoding.UTF8.GetBytes(text));
                        }
                    }
                    else if (text == "big1k")
                    {
                        text = new string('x', 1024 * 1);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big10k")
                    {
                        text = new string('x', 1024 * 10);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big100k")
                    {
                        text = new string('x', 1024 * 100);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big1m")
                    {
                        text = new string('x', 1024 * 1024 * 1);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big2m")
                    {
                        text = new string('x', 1024 * 1024 * 2);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big5m")
                    {
                        text = new string('x', 1024 * 1024 * 5);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big10m")
                    {
                        text = new string('x', 1024 * 1024 * 10);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big20m")
                    {
                        text = new string('x', 1024 * 1024 * 20);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big50m")
                    {
                        text = new string('x', 1024 * 1024 * 50);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big100m")
                    {
                        text = new string('x', 1024 * 1024 * 100);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big1g")
                    {
                        text = new string('x', 1024 * 1024 * 1024);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else
                    {
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            _client.Close();
            Console.WriteLine("TCP client has disconnected from server.");

            Console.ReadKey();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            ILog log = Logger.Get <Program>();

            var localActor = new RpcActor();

            var helloClient = new HelloClient(localActor);
            var calcClient  = new CalcClient(localActor);
            var orderClient = new OrderClient(localActor);

            localActor.RegisterRpcService(helloClient);
            localActor.RegisterRpcService(calcClient);
            localActor.RegisterRpcService(orderClient);

            localActor.Bootup();

            while (true)
            {
                try
                {
                    string text = Console.ReadLine().ToLowerInvariant().Trim();
                    if (text == "quit" || text == "exit")
                    {
                        break;
                    }
                    else if (text == "reconnect")
                    {
                        localActor.Shutdown();
                        localActor.Bootup();
                    }
                    else if (Regex.Match(text, @"^hello(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"^hello(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            Hello(log, helloClient);
                        }
                    }
                    else if (Regex.Match(text, @"^add(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"^add(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            Add(log, calcClient);
                        }
                    }
                    else if (Regex.Match(text, @"^order(\d*)$").Success)
                    {
                        var match      = Regex.Match(text, @"order(\d*)$");
                        int totalCalls = 0;
                        if (!int.TryParse(match.Groups[1].Value, out totalCalls))
                        {
                            totalCalls = 1;
                        }
                        for (int i = 0; i < totalCalls; i++)
                        {
                            PlaceOrder(log, orderClient);
                        }
                    }
                    else if (Regex.Match(text, @"^hello(\d+)x(\d+)$").Success)
                    {
                        var match       = Regex.Match(text, @"^hello(\d+)x(\d+)$");
                        int totalCalls  = int.Parse(match.Groups[1].Value);
                        int threadCount = int.Parse(match.Groups[2].Value);
                        Hello10000MultiThreading(log, helloClient, totalCalls, threadCount);
                    }
                    else if (Regex.Match(text, @"^add(\d+)x(\d+)$").Success)
                    {
                        var match       = Regex.Match(text, @"^add(\d+)x(\d+)$");
                        int totalCalls  = int.Parse(match.Groups[1].Value);
                        int threadCount = int.Parse(match.Groups[2].Value);
                        Add10000MultiThreading(log, calcClient, totalCalls, threadCount);
                    }
                    else
                    {
                        log.WarnFormat("Cannot parse the operation for input [{0}].", text);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
            }

            localActor.Shutdown();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            try
            {
                var config = new AsyncTcpSocketClientConfiguration();
                //config.UseSsl = true;
                //config.SslTargetHost = "Cowboy";
                //config.SslClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.cer"));
                //config.SslPolicyErrorsBypassed = false;

                //config.FrameBuilder = new FixedLengthFrameBuilder(20000);
                //config.FrameBuilder = new RawBufferFrameBuilder();
                //config.FrameBuilder = new LineBasedFrameBuilder();
                //config.FrameBuilder = new LengthPrefixedFrameBuilder();
                //config.FrameBuilder = new LengthFieldBasedFrameBuilder();

                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 22222);
                _client = new AsyncTcpSocketClient(remoteEP, new SimpleMessageDispatcher(), config);
                _client.Connect().Wait();

                Console.WriteLine("TCP client has connected to server [{0}].", remoteEP);
                Console.WriteLine("Type something to send to server...");
                while (true)
                {
                    try
                    {
                        string text = Console.ReadLine();
                        if (text == "quit")
                        {
                            break;
                        }
                        Task.Run(async() =>
                        {
                            if (text == "many")
                            {
                                text = new string('x', 8192);
                                for (int i = 0; i < 1000000; i++)
                                {
                                    await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text);
                                }
                            }
                            else if (text == "big1k")
                            {
                                text = new string('x', 1024 * 1);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else if (text == "big10k")
                            {
                                text = new string('x', 1024 * 10);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else if (text == "big100k")
                            {
                                text = new string('x', 1024 * 100);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else if (text == "big1m")
                            {
                                text = new string('x', 1024 * 1024 * 1);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else if (text == "big10m")
                            {
                                text = new string('x', 1024 * 1024 * 10);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else if (text == "big100m")
                            {
                                text = new string('x', 1024 * 1024 * 100);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else if (text == "big1g")
                            {
                                text = new string('x', 1024 * 1024 * 1024);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                            else
                            {
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length);
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.Get <Program>().Error(ex.Message, ex);
                    }
                }

                _client.Shutdown();
                Console.WriteLine("TCP client has disconnected from server [{0}].", remoteEP);
            }
            catch (Exception ex)
            {
                Logger.Get <Program>().Error(ex.Message, ex);
            }

            Console.ReadKey();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            StartServer();

            Console.WriteLine("TCP server has been started.");
            Console.WriteLine("Type something to send to client...");
            while (true)
            {
                try
                {
                    string text = Console.ReadLine();
                    if (text == "quit")
                    {
                        break;
                    }
                    else if (text == "many")
                    {
                        text = new string('x', 8192);
                        for (int i = 0; i < 1000000; i++)
                        {
                            _server.Broadcast(Encoding.UTF8.GetBytes(text));
                        }
                    }
                    else if (text == "big1")
                    {
                        text = new string('x', 1024 * 1024 * 1);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big2")
                    {
                        text = new string('x', 1024 * 1024 * 2);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big5")
                    {
                        text = new string('x', 1024 * 1024 * 5);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big10")
                    {
                        text = new string('x', 1024 * 1024 * 10);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big20")
                    {
                        text = new string('x', 1024 * 1024 * 20);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big50")
                    {
                        text = new string('x', 1024 * 1024 * 50);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big100")
                    {
                        text = new string('x', 1024 * 1024 * 100);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big1000")
                    {
                        text = new string('x', 1024 * 1024 * 1000);
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                    else
                    {
                        _server.Broadcast(Encoding.UTF8.GetBytes(text));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            _server.Shutdown();
            Console.WriteLine("TCP server has been stopped on [{0}].", _server.ListenedEndPoint);

            Console.ReadKey();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            try
            {
                var config = new TcpSocketSaeaClientConfiguration();

                //config.FrameBuilder = new FixedLengthFrameBuilder(20000);
                //config.FrameBuilder = new RawBufferFrameBuilder();
                //config.FrameBuilder = new LineBasedFrameBuilder();
                //config.FrameBuilder = new LengthPrefixedFrameBuilder();
                //config.FrameBuilder = new LengthFieldBasedFrameBuilder();

                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 22222);
                _client = new TcpSocketSaeaClient(remoteEP, new SimpleMessageDispatcher(), config);
                _client.Connect().Wait();

                Console.WriteLine("TCP client has connected to server [{0}].", remoteEP);
                Console.WriteLine("Type something to send to server...");
                while (true)
                {
                    try
                    {
                        string text = Console.ReadLine();
                        if (text == "quit")
                        {
                            break;
                        }
                        Task.Run(async() =>
                        {
                            if (text == "many")
                            {
                                text = new string('x', 8192);
                                for (int i = 0; i < 1000000; i++)
                                {
                                    await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text);
                                }
                            }
                            else if (text == "big")
                            {
                                text = new string('x', 1024 * 1024 * 100);
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text);
                            }
                            else
                            {
                                await _client.SendAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text);
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.Get <Program>().Error(ex.Message, ex);
                    }
                }

                _client.Close().Wait();
                Console.WriteLine("TCP client has disconnected from server [{0}].", remoteEP);
            }
            catch (Exception ex)
            {
                Logger.Get <Program>().Error(ex.Message, ex);
            }

            Console.ReadKey();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Specify that you want to use the NLog logging framework with MassTransit.
 /// </summary>
 /// <param name="configurator">Optional service bus configurator</param>
 public static void UseNLog(this IBusFactoryConfigurator configurator)
 {
     NLogLogger.Use();
 }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            NLogLogger.Use();

            try
            {
                var catalog = new AsyncWebSocketServerModuleCatalog();
                catalog.RegisterModule(new TestWebSocketModule());

                var config = new AsyncWebSocketServerConfiguration();
                //config.SslEnabled = true;
                //config.SslServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"D:\\Cowboy.pfx", "Cowboy");
                //config.SslPolicyErrorsBypassed = true;

                _server = new AsyncWebSocketServer(22222, catalog, config);
                _server.Listen();

                Console.WriteLine("WebSocket server has been started on [{0}].", _server.ListenedEndPoint);
                Console.WriteLine("Type something to send to clients...");
                while (true)
                {
                    try
                    {
                        string text = Console.ReadLine();
                        if (text == "quit")
                        {
                            break;
                        }
                        Task.Run(async() =>
                        {
                            if (text == "many")
                            {
                                text = new string('x', 8192);
                                for (int i = 0; i < 1000000; i++)
                                {
                                    await _server.BroadcastBinaryAsync(Encoding.UTF8.GetBytes(text));
                                    Console.WriteLine("WebSocket server [{0}] broadcasts binary -> [{1}].", _server.ListenedEndPoint, text);
                                }
                            }
                            else if (text == "big1")
                            {
                                text = new string('x', 1024 * 1024 * 1);
                                await _server.BroadcastBinaryAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("WebSocket server [{0}] broadcasts binary -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else if (text == "big10")
                            {
                                text = new string('x', 1024 * 1024 * 10);
                                await _server.BroadcastBinaryAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("WebSocket server [{0}] broadcasts binary -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else if (text == "big100")
                            {
                                text = new string('x', 1024 * 1024 * 100);
                                await _server.BroadcastBinaryAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("WebSocket server [{0}] broadcasts binary -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else if (text == "big1000")
                            {
                                text = new string('x', 1024 * 1024 * 1000);
                                await _server.BroadcastBinaryAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("WebSocket server [{0}] broadcasts binary -> [{1} Bytes].", _server.ListenedEndPoint, text.Length);
                            }
                            else
                            {
                                await _server.BroadcastBinaryAsync(Encoding.UTF8.GetBytes(text));
                                Console.WriteLine("WebSocket server [{0}] broadcasts binary -> [{1}].", _server.ListenedEndPoint, text);
                            }

                            //await _server.BroadcastText(text);
                            //Console.WriteLine("WebSocket server [{0}] broadcasts text -> [{1}].", _server.ListenedEndPoint, text);
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.Get <Program>().Error(ex.Message, ex);
                    }
                }

                _server.Shutdown();
                Console.WriteLine("WebSocket server has been stopped on [{0}].", _server.ListenedEndPoint);
            }
            catch (Exception ex)
            {
                Logger.Get <Program>().Error(ex.Message, ex);
            }

            Console.ReadKey();
        }
Exemplo n.º 12
0
        public servDCSGateway()
        {
            InitializeComponent();

            NLogLogger.Use();
        }