Пример #1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        public override void sendMessage(TOSERVERCOMMAND command, string senderName, string message, string receiverName)
        {
            base.sendMessage(command, senderName, message, receiverName);
            //if (serverClient==null)
            //{
            //    DelegateCollectionImpl.returnStringErrMsg("未打开监听");
            //    return;
            //}
            string[] commands = msg.ToString().Split(new char[] { '|' });
            bool     status   = true;

            serverClient.decodeCommands(commands, ref status);
        }
Пример #2
0
        /// <summary>
        /// 解析收到的数据
        /// </summary>
        /// <param name="commands"></param>
        /// <param name="status">登录状态</param>
        internal void decodeCommands(string[] commands, ref bool status)
        {
            if (status == false)
            {
                if ((TOSERVERCOMMAND)Enum.Parse(typeof(TOSERVERCOMMAND), commands[0]) == TOSERVERCOMMAND.CONN)
                {
                    conn(commands, ref status);
                }
                else
                {
                    sendMsg(currentSocket, "ERR|Please connect first");
                }
            }
            else
            {
                if (commands != null)
                {
                    TOSERVERCOMMAND cmd = (TOSERVERCOMMAND)Enum.Parse(typeof(TOSERVERCOMMAND), commands[0]);
                    switch (cmd)
                    {
                    case TOSERVERCOMMAND.LIST:
                        list(commands);
                        break;

                    case TOSERVERCOMMAND.PUB:
                        pub(commands);
                        break;

                    case TOSERVERCOMMAND.PRI:
                        pri(commands);
                        break;

                    case TOSERVERCOMMAND.EXIT:
                        exit(commands);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// 发消息
        /// </summary>
        /// <param name="command">命令</param>
        /// <param name="senderName">发送者姓名</param>
        /// <param name="message">消息</param>
        /// <param name="receiverName">接受者姓名</param>
        public virtual void sendMessage(TOSERVERCOMMAND command, string senderName = null, string message = null, string receiverName = null)
        {
            switch (command)
            {
            case TOSERVERCOMMAND.LIST:
                msg.Append(TOSERVERCOMMAND.LIST.ToString());
                break;

            case TOSERVERCOMMAND.PUB:
                msg.Append(TOSERVERCOMMAND.LIST.ToString()).Append("|").Append(senderName).Append(":|").Append(message);
                break;

            case TOSERVERCOMMAND.PRI:
                msg.Append(TOSERVERCOMMAND.LIST.ToString()).Append("|").Append(senderName).Append(":|").Append(receiverName).Append("|").Append(message);
                break;

            case TOSERVERCOMMAND.EXIT:
                msg.Append(TOSERVERCOMMAND.LIST.ToString());
                break;

            default:
                break;
            }
        }