Пример #1
0
        void CreateClient()
        {
            // Create the client
            var client = new SimplSocketClient();

            // Make the client connect automatically
            client.AutoConnect();

            // Wait until the connection is actually made
            client.WaitForConnection();

            // Create a byte array to send
            var arrayToSend1 = new byte[1000];

            // Send it
            client.Send(arrayToSend1);

            // Get a byte array from the memory pool
            var arrayToSend2 = PooledMessage.Rent(1000);

            client.Send(arrayToSend2);

            // We will not dispose the message directly, since it may still need to be send
            // Instead we use the ReturnAfterSend, which will return the message to the pool after sending
            arrayToSend2.ReturnAfterSend();
        }
Пример #2
0
        private void SendBenchmark(SimplSocketClient client)
        {
            Log("*** SendBenchmark ***");
            var rnd         = new Random();
            var bufferSizes = new[] { 1, 10, 100, 1000 };
            var length      = 0;

            for (var test = 0; test < 4; test++)
            {
                byte[] randomData = new byte[bufferSizes[test] * 512];
                length += randomData.Length;
                rnd.NextBytes(randomData);

                var countPerIteration = 100;
                var watch             = Stopwatch.StartNew();
                for (var i = 0; i < countPerIteration; i++)
                {
                    randomData = new byte[bufferSizes[test] * 512];

                    if (!client.IsConnected())
                    {
                        client.Connect(new IPEndPoint(IPAddress.Loopback, 5000));
                    }

                    client.Send(randomData);
                }

                watch.Stop();
                var speed       = (countPerIteration * length) / (watch.ElapsedMilliseconds / 1000.0);
                var scaledSpeed = ScaledSpeed(speed);
                Log($"{countPerIteration}x{length}: {watch.ElapsedMilliseconds}ms = {scaledSpeed} ");
            }
        }
Пример #3
0
        public void Send <TIn>(string identifier, TIn message)
        {
            var rawMessage = _serializer.Serialize(identifier, message);

            if (rawMessage == null)
            {
                return;
            }
            _simplSocketClient.Send(rawMessage);
        }