Пример #1
0
        public override void OnReceived(IConnection connection, IRecvivedMessageInfo <CommandLineMessage> recvivedMessageInfo)
        {
            base.OnReceived(connection, recvivedMessageInfo);
            var cmd = recvivedMessageInfo.Message;

            System.Threading.Interlocked.Increment(ref count);

            switch (cmd.CmdName)
            {
            case "echo":
                recvivedMessageInfo.Reply(new CommandLineMessage("echo_reply", cmd.Parameters), connection);
                break;

            case "init":
                recvivedMessageInfo.Reply(new CommandLineMessage("init_reply", new[] { "ok" }), connection);
                break;

            default:
                recvivedMessageInfo.Reply(new CommandLineMessage("error unknow command "), connection);
                break;
            }
            if (count % 2000 == 100)
            {
                Console.WriteLine($"connection:\t{connection.ConnectionID}\t{recvivedMessageInfo.Message}");
                connection.BeginSend(new CommandLineMessage("hello!!!!!!"));
            }
        }
Пример #2
0
        public override void OnReceived(IConnection connection, IRecvivedMessageInfo <ThriftMessage> recvivedMessageInfo)
        {
            base.OnReceived(connection, recvivedMessageInfo);
            var cmd = recvivedMessageInfo.Message;

            System.Threading.Interlocked.Increment(ref count);
            var arr = cmd.Text.Split(' ');

            switch (arr[0])
            {
            case "echo":
                recvivedMessageInfo.Reply(new ThriftMessage(string.Join(" ", "echo_reply", arr[1], arr[2])), connection);
                break;

            case "init":
                recvivedMessageInfo.Reply(new ThriftMessage("init_reply ok"), connection);
                break;

            default:
                recvivedMessageInfo.Reply(new ThriftMessage("error unknow command "), connection);
                break;
            }
            if (count % 2000 == 100)
            {
                Console.WriteLine($"connection:\t{connection.ConnectionID}\t{recvivedMessageInfo.Message}");
                connection.BeginSend(new ThriftMessage("hello!!!!"));
            }
        }