Exemplo n.º 1
0
        private static void OperationSocketData(int receiveLength, SocketP2PEntity client)
        {
            try
            {
                SendToClientCompleteHandler sendToClientCompleteHandler = new SendToClientCompleteHandler(SendToClientComplete);
                OutPutSystemMessageHandler  outPutSystemMessageHandler  = new OutPutSystemMessageHandler(OutPutSystemMessage);

                string json = Encoding.UTF8.GetString(client.Buffer, 0, receiveLength);

                if (string.IsNullOrEmpty(json))
                {
                    LogCommonHelper.WriteLog("p2p服务接收到数据:Null");
                }
                else
                {
                    LogCommonHelper.WriteLog("p2p服务接收到数据:" + json);

                    SocketP2PMessageEntity message = JsonHelper.Deserialize <SocketP2PMessageEntity>(json);

                    ManagerIdentity.Execute(client, message, Clients, Queue, sendToClientCompleteHandler, outPutSystemMessageHandler);
                }
            }
            catch (Exception ex)
            {
                LogCommonHelper.WriteLog("OperationSocketData:" + ex.InnerException.Message);
            }
        }
Exemplo n.º 2
0
        protected override void ValidateIdentity(SocketP2PEntity client, SocketP2PMessageEntity message,
                                                 List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                                                 SendToClientCompleteHandler sendToClientCompleteHandler, OutPutSystemMessageHandler outPutSystemMessageHandler)
        {
            try
            {
                LogCommonHelper.WriteLog("我是客服,等待访客请求");

                var PreparingMessageEntity = NewP2PMessage();
                PreparingMessageEntity.Sender   = null;
                PreparingMessageEntity.Receiver = client.Sender;
                PreparingMessageEntity.Identity = "SERVER";
                PreparingMessageEntity.Data     = string.Format("您好,客服({0}),请您等待访客请求...", client.Sender);
                PreparingMessageEntity.Owner    = client.Owner;
                PreparingMessageEntity.WeiXinNo = client.WeiXinNo;
                PreparingMessageEntity.OpenId   = client.OpenId;

                SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
            }
            catch (SocketException ex)
            {
                client.Socket.Close();
                clients.Remove(client);
                outPutSystemMessageHandler(ex.Message);
            }
        }
Exemplo n.º 3
0
 // 处理异常
 private static void ExecuteException(SocketP2PEntity client, SocketException ex)
 {
     // 在服务端记录异常信息,关闭导致异常的 Socket,并将其清除出访客端 Socket 列表
     OutPutSystemMessage(string.Format("异常:ID[{0}],IP[{1}],Msg[{2}]", client.ID, client.Socket.RemoteEndPoint.ToString(), ex.Message));
     client.Socket.Close();
     Clients.Remove(client);
     Thread.Sleep(100);
 }
Exemplo n.º 4
0
        protected virtual void SendMessageToTerminal(SocketP2PMessageEntity message, SocketP2PEntity client,
                                                     SendToClientCompleteHandler sendToClientCompleteHandler)
        {
            try
            {
                if (!string.IsNullOrEmpty(client.OpenId))
                {
                    LogCommonHelper.WriteLog("Identity : " + message.Identity);

                    string data = message.Data;
                    if (Equals(message.Identity, "CUSTOMER"))
                    {
                        data = string.Format("访客({0}) {1} : {2}", message.Sender, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), message.Data);
                    }

                    string msg = "{\"touser\":\"" + client.OpenId + "\",\"msgtype\":\"text\", \"text\":{\"content\":\"" + data + "\"}}";
                    LogCommonHelper.WriteLog("msg:" + msg);

                    if (!string.IsNullOrEmpty(msg))
                    {
                        WxAccountService.WxAccountServiceSoapClient WxAccount       = new WxAccountService.WxAccountServiceSoapClient();
                        WxAccountService.WxAccountEntity            WxAccountEntity = WxAccount.GetByWeiXinNo(message.WeiXinNo);
                        if (WxAccountEntity == null)
                        {
                            LogCommonHelper.WriteLog("WxAccount为NULL"); return;
                        }

                        LogCommonHelper.WriteLog("已经获取WxAccount信息");
                        LogCommonHelper.WriteLog("UserName : "******"Token : " + WxAccountEntity.Token);
                        LogCommonHelper.WriteLog("AppId : " + WxAccountEntity.AppId);
                        LogCommonHelper.WriteLog("Secret : " + WxAccountEntity.Secret);

                        string un    = WxAccountEntity.UserName;
                        string unkey = CryptHelper.MD5(string.Format("{0}{1}", un, WxAccountEntity.Token));
                        string url   = string.Format("{0}?key=C011&un={1}&unkey={2}", ConfigurationHelper.Get("WxUrl"), un, unkey);
                        LogCommonHelper.WriteLog("URL:" + url);
                        string strReply = WebHelper.GetFormWebRequest(url, "POST", "body=" + msg);
                    }
                }
                else
                {
                    string json = JsonHelper.Serialize(message);
                    LogCommonHelper.WriteLog("发送Socket消息,内容:" + json);
                    byte[] buffer = Encoding.UTF8.GetBytes(json);
                    client.Socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(sendToClientCompleteHandler), client);
                }
            }
            catch (Exception ex)
            {
                LogCommonHelper.WriteLog("SendMessageToTerminal Exception:" + ex.InnerException.Message);
            }
        }
Exemplo n.º 5
0
        public void Comunicate(SocketP2PEntity client, SocketP2PMessageEntity message,
                               List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                               SendToClientCompleteHandler sendToClientCompleteHandler, OutPutSystemMessageHandler outPutSystemMessageHandler)
        {
            if (string.IsNullOrEmpty(message.Receiver))
            {
                if (Equals(message.Data, "CHECKIDENTITY"))
                {
                    if (client == null)
                    {
                        client = new SocketP2PEntity();
                    }
                    // 初始化访客端
                    client.Sender   = message.Sender;
                    client.Receiver = null;
                    client.Owner    = message.Owner;
                    client.Identity = message.Identity;
                    client.WeiXinNo = message.WeiXinNo;
                    client.OpenId   = message.OpenId;
                    // 放入访客端集合
                    //if (!clients.Exists(x => x.Sender == client.Sender))
                    //{
                    // 允许多窗口对话
                    clients.Add(client);
                    //}

                    ValidateIdentity(client, message, clients, queue, sendToClientCompleteHandler, outPutSystemMessageHandler);
                }
                else
                {
                    var PreparingMessageEntity = NewP2PMessage();
                    PreparingMessageEntity.Sender   = null;
                    PreparingMessageEntity.Receiver = client.Sender;
                    PreparingMessageEntity.Identity = "SERVER";
                    PreparingMessageEntity.Data     = (message.Identity == "SERVANT")
                        ? string.Format("您好,客服({0}),请您等待访客请求后发言", client.Sender)
                        : string.Format("您好,访客({0}),请您等待客服响应后发言", client.Sender);
                    PreparingMessageEntity.Owner    = message.Owner;
                    PreparingMessageEntity.WeiXinNo = message.WeiXinNo;
                    PreparingMessageEntity.OpenId   = message.OpenId;

                    SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
                }
            }
            else
            {
                // 记录消息
                var entity = SaveEntity(client, message);
                // 回发消息
                Sending(entity, client, message, clients, queue, sendToClientCompleteHandler, outPutSystemMessageHandler);
            }
        }
Exemplo n.º 6
0
        private static byte[] GetWillSendDataByServer(SocketP2PEntity client, string data)
        {
            SocketP2PMessageEntity message = new SocketP2PMessageEntity();

            message.Sender   = ConstHelper.SERVER_ID;
            message.Receiver = ConstHelper.SERVER_ID;
            message.DialogId = ConstHelper.DIALOG_NO;
            message.Identity = "SERVER";
            message.Data     = data;

            string buffer = JsonHelper.Serialize(message);

            return(Encoding.Default.GetBytes(buffer));
        }
Exemplo n.º 7
0
        private TEntity SaveEntity(SocketP2PEntity client, SocketP2PMessageEntity message)
        {
            TEntity entity = new TEntity();

            entity.DialogContent = message.Data;
            entity.DialogTime    = DateTime.Now;
            entity.FromId        = message.Sender;
            entity.ToId          = message.Receiver;

            //TRepository repository = new TRepository();
            //repository.Add(entity);

            return(entity);
        }
Exemplo n.º 8
0
        private void Sending(TEntity entity, SocketP2PEntity client, SocketP2PMessageEntity message,
                             List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                             SendToClientCompleteHandler sendToClientCompleteHandler, OutPutSystemMessageHandler outPutSystemMessageHandler)
        {
            if (message.Identity == "SERVER")
            {
                LogCommonHelper.WriteLog(string.Format("由系统发给{0}({1})的消息",
                                                       message.Receiver.Length == 10 ? "访客" : "客服",
                                                       message.Receiver));

                SendMessageToTerminal(message, client, sendToClientCompleteHandler);
            }
            else
            {
                SendingByRuler(entity, client, message, clients, queue, sendToClientCompleteHandler, outPutSystemMessageHandler);
            }
        }
Exemplo n.º 9
0
        // 结束发送
        private static void SendToClientComplete(IAsyncResult async)
        {
            SocketP2PEntity client = async.AsyncState as SocketP2PEntity;

            try
            {
                // 完成将信息发送到访客端的这个异步操作
                if (client.Socket.Connected)
                {
                    client.Socket.EndSend(async);
                }
            }
            catch (SocketException ex)
            {
                ExecuteException(client, ex);
            }
        }
Exemplo n.º 10
0
        public static void Execute(SocketP2PEntity client, SocketP2PMessageEntity message,
                                   List <SocketP2PEntity> Clients, List <SocketP2PEntity> Queue,
                                   SendToClientCompleteHandler SendToClientCompleteHandler, OutPutSystemMessageHandler OutPutSystemMessageHandler)
        {
            IIdentity id = null;

            switch (message.Identity.ToUpper())
            {
            case "CUSTOMER":
                id = new CustomerIdentity();
                break;

            case "SERVANT":
                id = new ServantIdentity();
                break;
            }

            id.Comunicate(client, message, Clients, Queue, SendToClientCompleteHandler, OutPutSystemMessageHandler);
        }
Exemplo n.º 11
0
        // 访客端连接完成的回调函数
        private static void ClientConnectComplete(IAsyncResult async)
        {
            SocketP2PEntity client = new SocketP2PEntity();

            client.Socket = Server.EndAccept(async);
            // 在各自项目中自行处理
            // clients.Add(client);

            // 开始接收访客端数据
            try
            {
                client.Socket.BeginReceive(client.Buffer, 0, client.Buffer.Length, SocketFlags.None, new AsyncCallback(ClientReceiveComplete), client);
            }
            catch (SocketException ex)
            {
                ExecuteException(client, ex);
            }

            Server.BeginAccept(new AsyncCallback(ClientConnectComplete), null);
        }
Exemplo n.º 12
0
        // 访客端数据接收的回调函数
        private static void ClientReceiveComplete(IAsyncResult async)
        {
            SocketP2PEntity client         = async.AsyncState as SocketP2PEntity;
            int             _receiveLength = 0;

            try
            {
                if (client.Socket.Connected)
                {
                    _receiveLength = client.Socket.EndReceive(async);
                    // 自定义处理
                    OperationSocketData(_receiveLength, client);
                }
                else
                {
                    client.Socket.Close();
                    Clients.Remove(client);
                }
            }
            catch (SocketException ex)
            {
                ExecuteException(client, ex);
            }

            try
            {
                if (client.Socket.Connected)
                {
                    client.Socket.BeginReceive(client.Buffer, 0, client.Buffer.Length, 0, new AsyncCallback(ClientReceiveComplete), client);
                }
                else
                {
                    client.Socket.Close();
                    Clients.Remove(client);
                }
            }
            catch (SocketException ex)
            {
                ExecuteException(client, ex);
            }
        }
Exemplo n.º 13
0
        protected override void ValidateIdentity(SocketP2PEntity client, SocketP2PMessageEntity message, List <SocketP2PEntity> clients,
                                                 List <SocketP2PEntity> queue, SendToClientCompleteHandler sendToClientCompleteHandler,
                                                 OutPutSystemMessageHandler outPutSystemMessageHandler)
        {
            LogCommonHelper.WriteLog("开始分配客服");
            LogCommonHelper.WriteLog("客户端数量:" + clients.Count);

            var servants = clients.Where(x => x.Identity == "SERVANT" &&
                                         (x.Owner == message.Owner || x.WeiXinNo == message.WeiXinNo) &&
                                         x.Receiver == null);

            LogCommonHelper.WriteLog("空闲的客服数量:" + servants.Count());

            var servant = servants.FirstOrDefault();

            bool isSuccess = false;

            if (servant != null)
            {
                #region ==== 随机分配客服 ====
                LogCommonHelper.WriteLog("随机分配客服");
                servant.Receiver = client.Sender;
                client.Receiver  = servant.Sender;
                try
                {
                    if (servant.Socket.Connected)
                    {
                        var PreparingMessageEntity = NewP2PMessage();
                        PreparingMessageEntity.Sender   = servant.Receiver;
                        PreparingMessageEntity.Receiver = servant.Sender;
                        PreparingMessageEntity.Identity = "SERVER";
                        PreparingMessageEntity.Data     = string.Format("您好,访客({0}),需要您的服务", servant.Receiver);
                        PreparingMessageEntity.Owner    = servant.Owner;
                        PreparingMessageEntity.WeiXinNo = servant.WeiXinNo;
                        PreparingMessageEntity.OpenId   = servant.OpenId;

                        SendMessageToTerminal(PreparingMessageEntity, servant, sendToClientCompleteHandler);

                        isSuccess = true;

                        if (queue.Exists(x => x.Sender == client.Sender))
                        {
                            queue.Remove(client);
                        }
                    }
                }
                catch (SocketException ex)
                {
                    servant.Socket.Close();
                    clients.Remove(servant);
                    outPutSystemMessageHandler(ex.Message);
                    return;
                }
                #endregion

                Thread.Sleep(500);

                if (isSuccess)
                {
                    #region ==== 分配成功, 向访客发送消息 ====
                    try
                    {
                        LogCommonHelper.WriteLog("分配成功,向访客发送消息");
                        // 更新发言时间
                        client.LastTalkTime = DateTime.Now;
                        // 发送消息
                        if (client.Socket.Connected)
                        {
                            var PreparingMessageEntity = NewP2PMessage();
                            PreparingMessageEntity.Sender   = client.Receiver;
                            PreparingMessageEntity.Receiver = client.Sender;
                            PreparingMessageEntity.Identity = "SERVER";
                            PreparingMessageEntity.Data     = string.Format("您好,客服({0}),正在为您服务,如果超过3分钟未发言,系统自动将您断线", client.Receiver);
                            PreparingMessageEntity.Owner    = client.Owner;
                            PreparingMessageEntity.WeiXinNo = client.WeiXinNo;
                            PreparingMessageEntity.OpenId   = client.OpenId;

                            SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
                        }
                    }
                    catch (SocketException ex)
                    {
                        client.Socket.Close();
                        clients.Remove(client);
                        outPutSystemMessageHandler(ex.Message);
                    }
                    #endregion
                }
                else
                {
                    #region ==== 客服已经断线 ====
                    try
                    {
                        LogCommonHelper.WriteLog("客服已经断线,请刷新后重新连接");
                        client.Receiver = null;
                        client.DialogId = null;
                        var PreparingMessageEntity = NewP2PMessage();
                        PreparingMessageEntity.Sender   = null;
                        PreparingMessageEntity.Receiver = client.Sender;
                        PreparingMessageEntity.Identity = "SERVER";
                        PreparingMessageEntity.Data     = "客服已经断线,请刷新后重新连接";
                        PreparingMessageEntity.Owner    = client.Owner;
                        PreparingMessageEntity.WeiXinNo = client.WeiXinNo;
                        PreparingMessageEntity.OpenId   = client.OpenId;

                        SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
                    }
                    catch (SocketException ex)
                    {
                        client.Socket.Close();
                        clients.Remove(client);
                        outPutSystemMessageHandler(ex.Message);
                    }
                    #endregion
                }
            }
            else
            {
                #region ==== 客服全忙 ====
                LogCommonHelper.WriteLog("客服全忙");
                try
                {
                    if (client.Socket.Connected)
                    {
                        LogCommonHelper.WriteLog("正在加入队列");
                        if (!queue.Exists(x => x.Sender == message.Sender))
                        {
                            queue.Add(client);
                        }

                        int i = queue.IndexOf(client);
                        int n = i + 1;

                        var PreparingMessageEntity = NewP2PMessage();
                        PreparingMessageEntity.Sender   = null;
                        PreparingMessageEntity.Receiver = client.Sender;
                        PreparingMessageEntity.Identity = "SERVER";
                        PreparingMessageEntity.Data     = (i == 0)
                            ? string.Format("抱歉,客服全忙。系统自动为您排队,队列序号{0},客服即将为您服务,请耐心等待", n, i)
                            : string.Format("抱歉,客服全忙。系统自动为您排队,队列序号{0},您前面还有{1}人", n, i);
                        PreparingMessageEntity.Owner    = client.Owner;
                        PreparingMessageEntity.WeiXinNo = client.WeiXinNo;
                        PreparingMessageEntity.OpenId   = client.OpenId;

                        SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
                    }
                }
                catch (SocketException ex)
                {
                    client.Socket.Close();
                    clients.Remove(client);
                    outPutSystemMessageHandler(ex.Message);
                }
                #endregion
            }
        }
Exemplo n.º 14
0
 protected abstract void SendingByRuler(TEntity entity, SocketP2PEntity client, SocketP2PMessageEntity message,
                                        List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                                        SendToClientCompleteHandler sendToClientCompleteHandler, OutPutSystemMessageHandler outPutSystemMessageHandler);
Exemplo n.º 15
0
 protected abstract void ValidateIdentity(SocketP2PEntity client, SocketP2PMessageEntity message,
                                          List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                                          SendToClientCompleteHandler sendToClientCompleteHandler,
                                          OutPutSystemMessageHandler outPutSystemMessageHandler);
Exemplo n.º 16
0
        protected override void SendingByRuler(DialogInfoEntity entity,
                                               SocketP2PEntity client, SocketP2PMessageEntity message,
                                               List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                                               SendToClientCompleteHandler sendToClientCompleteHandler, OutPutSystemMessageHandler outPutSystemMessageHandler)
        {
            if (message.Data.Replace(" ", "").ToLower() == "exitall")
            {
                LogCommonHelper.WriteLog("客服全部退出");
                clients.RemoveAll(x => x.Sender == message.Sender && (x.Owner == message.Owner || x.WeiXinNo == message.WeiXinNo));
            }
            else if (message.Data.Replace(" ", "").ToLower() == "exit")
            {
                LogCommonHelper.WriteLog(string.Format("客服({0})退出", message.Sender));
                clients.RemoveAll(x => x.Sender == message.Sender && x.Receiver == message.Receiver);
            }
            else
            {
                LogCommonHelper.WriteLog("由客服发来的消息,发给访客" + message.Receiver);

                var customer = clients.Where(x => x.Sender == message.Receiver).FirstOrDefault();
                if (customer != null)
                {
                    try
                    {
                        LogCommonHelper.WriteLog("开始向访客发送消息");
                        // 记录最后通话时间
                        customer.LastTalkTime = DateTime.Now;

                        var PreparingMessageEntity = NewP2PMessage();
                        PreparingMessageEntity.Sender   = customer.Receiver;
                        PreparingMessageEntity.Receiver = customer.Sender;
                        PreparingMessageEntity.Data     = message.Data;
                        PreparingMessageEntity.Owner    = customer.Owner;
                        PreparingMessageEntity.Identity = "SERVANT";
                        PreparingMessageEntity.WeiXinNo = customer.WeiXinNo;
                        PreparingMessageEntity.OpenId   = customer.OpenId;

                        SendMessageToTerminal(PreparingMessageEntity, customer, sendToClientCompleteHandler);
                    }
                    catch (SocketException ex)
                    {
                        client.Socket.Close();
                        clients.Remove(client);
                        outPutSystemMessageHandler(ex.Message);
                    }
                }
                else
                {
                    var servant = clients.Where(x => x.Receiver == message.Receiver).FirstOrDefault();
                    if (servant != null)
                    {
                        try
                        {
                            LogCommonHelper.WriteLog("向客服发送访客断线的消息");

                            var PreparingMessageEntity = NewP2PMessage();
                            PreparingMessageEntity.Sender   = null;
                            PreparingMessageEntity.Receiver = servant.Sender;
                            PreparingMessageEntity.Identity = "SERVER";
                            PreparingMessageEntity.Data     = string.Format("访客({0})已经断线,请您等待其他的访客请求...", message.Receiver);
                            PreparingMessageEntity.Owner    = servant.Owner;
                            PreparingMessageEntity.WeiXinNo = servant.WeiXinNo;
                            PreparingMessageEntity.OpenId   = servant.OpenId;

                            servant.Receiver = null;
                            SendMessageToTerminal(PreparingMessageEntity, servant, sendToClientCompleteHandler);
                        }
                        catch (SocketException ex)
                        {
                            client.Socket.Close();
                            clients.Remove(client);
                            outPutSystemMessageHandler(ex.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        protected override void SendingByRuler(DialogInfoEntity entity, SocketP2PEntity client, SocketP2PMessageEntity message,
                                               List <SocketP2PEntity> clients, List <SocketP2PEntity> queue,
                                               SendToClientCompleteHandler sendToClientCompleteHandler,
                                               OutPutSystemMessageHandler outPutSystemMessageHandler)
        {
            LogCommonHelper.WriteLog("由访客发来的消息,发给客服" + message.Receiver);

            var servant = clients.Where(x => x.Receiver == message.Sender).FirstOrDefault();

            if (servant != null && servant.Socket.Connected)
            {
                try
                {
                    client.LastTalkTime = DateTime.Now;

                    var PreparingMessageEntity = NewP2PMessage();
                    PreparingMessageEntity.Sender   = servant.Receiver;
                    PreparingMessageEntity.Receiver = servant.Sender;
                    PreparingMessageEntity.Data     = message.Data;
                    PreparingMessageEntity.Owner    = servant.Owner;
                    PreparingMessageEntity.Identity = "CUSTOMER";
                    PreparingMessageEntity.WeiXinNo = servant.WeiXinNo;
                    PreparingMessageEntity.OpenId   = servant.OpenId;

                    SendMessageToTerminal(PreparingMessageEntity, servant, sendToClientCompleteHandler);
                }
                catch (SocketException ex)
                {
                    client.Socket.Close();
                    clients.Remove(client);
                    outPutSystemMessageHandler(ex.Message);
                }
            }
            else if (queue.Where(x => x.Sender == message.Sender).Any())
            {
                try
                {
                    client.LastTalkTime = DateTime.Now;
                    int i = queue.IndexOf(client) + 1;

                    var PreparingMessageEntity = NewP2PMessage();
                    PreparingMessageEntity.Sender   = null;
                    PreparingMessageEntity.Receiver = client.Sender;
                    PreparingMessageEntity.Identity = "SERVER";
                    PreparingMessageEntity.Data     = string.Format("您正在排队,队列序号{0},您前面还有{1}人", i, i - 1);
                    PreparingMessageEntity.Owner    = client.Owner;
                    PreparingMessageEntity.WeiXinNo = client.WeiXinNo;
                    PreparingMessageEntity.OpenId   = client.OpenId;

                    SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
                }
                catch (SocketException ex)
                {
                    client.Socket.Close();
                    clients.Remove(client);
                    outPutSystemMessageHandler(ex.Message);
                }
            }
            else
            {
                try
                {
                    var PreparingMessageEntity = NewP2PMessage();
                    PreparingMessageEntity.Sender   = null;
                    PreparingMessageEntity.Receiver = client.Sender;
                    PreparingMessageEntity.Identity = "SERVER";
                    PreparingMessageEntity.Data     = "客服已经断线,请刷新后重新连接";
                    PreparingMessageEntity.Owner    = client.Owner;
                    PreparingMessageEntity.WeiXinNo = client.WeiXinNo;
                    PreparingMessageEntity.OpenId   = client.OpenId;

                    SendMessageToTerminal(PreparingMessageEntity, client, sendToClientCompleteHandler);
                }
                catch (SocketException ex)
                {
                    client.Socket.Close();
                    clients.Remove(client);
                    outPutSystemMessageHandler(ex.Message);
                }
            }
        }