Esempio n. 1
0
        private static void OnFrame(ServerClient channel, MessageFrame frame)
        {
            var msg = Encoding.ASCII.GetString(frame.PayloadBuffer.Array, frame.PayloadBuffer.Offset,
                frame.PayloadBuffer.Count);

            Console.WriteLine("Received '" + msg + "' from " + channel.RemoteEndPoint);
        }
Esempio n. 2
0
        private void OnFrame(ServerClient channel, MessageFrame frame)
        {
            if (frame.SequenceNumber == 65535)
            {
                _batchCounter ++;
                Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " " + (_batchCounter*65535) + " messages.");
            }

            if (frame.Payload != null)
            {
                if (frame.Payload.ToString()[0] == 'm')
                {
                    Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " done");
                    var buffer = Encoding.ASCII.GetBytes("completed");
                    channel.Send(new MessageFrame(buffer));
                }

            }
            else if (frame.PayloadBuffer.Array[1] == 'm')
            {
                Console.WriteLine(DateTime.UtcNow.ToString("HH:mm:ss.fff") + " done");
                var buffer = Encoding.ASCII.GetBytes("completed");
                channel.Send(new MessageFrame(buffer));
            }
        }
Esempio n. 3
0
 private void OnClientDisconnect(ServerClient arg1, SocketError arg2)
 {
     Console.WriteLine("Disconnected");
     _timeSyncCompleted = false;
     _completedEvent.Set();
     _batchCounter = 0;
 }
        private void OnAccept(IAsyncResult ar)
        {
            try
            {
                var socket = _listener.EndAcceptSocket(ar);
                _listener.BeginAcceptSocket(OnAccept, null);

                ServerClient connection;
                if (!_availableClientPool.TryDequeue(out connection))
                {
                    Console.WriteLine("Allocating new client");
                    connection = new ServerClient(ServerName, _extensionProvider, _bufferManager)
                    {
                        FrameReceived = FrameReceived
                    };
                    connection.Disconnected += OnDisconnected;
                    connection.Start(socket);
                }
                else
                {
                    Console.WriteLine("Reusing client");
                    connection.Start(socket);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        private void OnFrame(ServerClient arg1, MessageFrame arg2)
        {
            var destination = arg2.Destination;
            IMessagingService service;
            if (!_items.TryGetValue(destination, out service))
            {
                if (destination.StartsWith("topic/"))
                {
                    if (!AllowDynamicTopics)
                    {
                        var errorFrame = new ErrorFrame("Topics must exist before messages are sent. Cannot create " + destination);
                        //arg1.Send(errorFrame);
                    }
                }

            }
        }
Esempio n. 6
0
        private void OnTimeSync(ServerClient channel, MessageFrame frame)
        {
            if (_timeSyncCompleted)
            {
                OnFrame(channel, frame);
                return;
            }

            var data = Encoding.ASCII.GetString(frame.PayloadBuffer.Array, frame.PayloadBuffer.Offset,
                frame.PayloadBuffer.Count);

            var parts = data.Split(';');
            var time = DateTime.Parse(parts[0]);

            var buffer =
                Encoding.ASCII.GetBytes((int)DateTime.UtcNow.Subtract(time).TotalMilliseconds + ";" +
                                        DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.ffff"));
            channel.Send(new MessageFrame(buffer));

            //completed time sync
            if (parts.Length == 2)
            {
                Console.WriteLine("Time synchronization completed");
                _timeSyncCompleted = true;
            }
        }