示例#1
0
        static void Exec(IMClientEngine client)
        {
            Print();

            ulong currentUserId = 0;

            while (true)
            {
                try
                {
                    string key = Console.ReadLine();
                    if (key?.ToLower() == "q")
                    {
                        break;
                    }
                    else if (key.StartsWith("login"))
                    {
                        string[] parameters = key.Split(' ');
                        currentUserId = ulong.Parse(parameters[1]);
                        UserLogin(client, currentUserId, parameters[2]);
                    }
                    else if (key.StartsWith("connect"))
                    {
                        client.Connect();
                        ClientConfig.WriteLine($"Current client endpoint: {client.LocalAddress}", ConsoleColor.Green);
                    }
                    else if (key.StartsWith("logout"))
                    {
                        client.Stop();
                        break;
                    }
                    else if (key.StartsWith("user"))
                    {
                        string[] parameters = key.Split(' ');
                        User(client, currentUserId, ulong.Parse(parameters[1]), parameters[2]);
                    }
                    else if (key.StartsWith("group"))
                    {
                        string[] parameters = key.Split(' ');
                        Group(client, currentUserId, parameters[1], parameters[2]);
                    }
                    else
                    {
                        Print();
                    }
                }
                catch (Exception ex)
                {
                    Print();
                    ClientConfig.WriteLine(ex.ToString(), ConsoleColor.Red);
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            LogHelper.InitConfigure();

            IMClientEngine client = new IMClientEngine("127.0.0.1", 8050, clientListener: new IMClientLisenter());

            client.Register(new ClientPingExecutor());
            client.Register(new UserExecutor());
            client.Register(new GroupExecutor());
            client.GlobalMessageHead = new ImMessageHead()
            {
                Client   = "windows",
                Language = "c#",
                //Session = null,
                Version   = "1.0.0",
                Timestamp = 0,
            };
            Console.WriteLine($"Connecting to server({client.Host}:{client.Port}) ...");
            client.Connect();
            ClientConfig.WriteLine($"Current client endpoint: {client.LocalAddress}", ConsoleColor.Green);

            Exec(client);
        }