Beispiel #1
0
 /// <summary>
 /// 给所有的客户端发送消息
 /// </summary>
 public void SendDataToAllClient(CometMessageAction action, String message)
 {
     foreach (var client in m_RegistryClients)
     {
         SendData(client, action, message);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 向单个客户端发送数据
        /// </summary>
        /// <param name="rsClient"></param>
        /// <param name="data"></param>
        /// <param name="isAsync">默认为异步调用</param>
        public void SendData(RegistryClient registryClient, CometMessageAction action, String data, Boolean isAsync = true)
        {
            try
            {
                CometMessage rm = new CometMessage()
                {
                    Action      = action,
                    MessageBody = data,
                    IsAsync     = isAsync
                };

                String messageData = XmlUtil.SaveXmlFromObj <CometMessage>(rm);
                Console.WriteLine("发送数据:{0}", messageData);

                Byte[] msg = Encoding.UTF8.GetBytes(messageData);
                registryClient.Socket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(SendCallback), registryClient);
            }
            catch (Exception ex)
            {
                XTrace.WriteLine("发送数据时发生异常:" + ex.ToString());
                lock (m_RegistryClients)
                {
                    m_RegistryClients.Remove(registryClient);
                    registryClient.Dispose();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 向服务器发送数据
        /// </summary>
        /// <param name="message"></param>
        /// <param name="isAsync">如过为同步调用,则在回传的是后需要释放同步信号</param>
        public void SendData(CometMessageAction action, String message, Boolean isAsync = true)
        {
            if (m_SocketClient == null || !m_SocketClient.Connected)
            {
                throw new Exception("无法连接服务器!");
            }

            try
            {
                CometMessage regMessage = new CometMessage()
                {
                    Action                = action,
                    IsAsync               = isAsync,
                    ClientType            = m_ClientType,
                    ClientVersion         = ESBProxy.GetInstance().Version.Replace("MB.ESB.Core ", ""),
                    ProcessorID           = Process.GetCurrentProcess().Id,
                    DotNetFramworkVersion = Environment.Version.ToString(),
                    OSVersion             = Environment.OSVersion.ToString(),
                    MessageBody           = message
                };

                String dataMessage = XmlUtil.SaveXmlFromObj <CometMessage>(regMessage);
                Console.WriteLine("发送数据:{0}", dataMessage);

                Byte[] data = Encoding.UTF8.GetBytes(dataMessage);
                m_SocketClient.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), m_SocketClient);
            }
            catch (Exception ex)
            {
                OnLostConnection(ex.ToString());
            }
        }
Beispiel #4
0
 /// <summary>
 /// 给所有的客户端发送消息
 /// </summary>
 public void SendDataToAllClient(CometMessageAction action, String message)
 {
     foreach (var client in m_RegistryClients)
     {
         SendData(client, action, message);
     }
 }
Beispiel #5
0
        /// <summary>
        /// 向单个客户端发送数据
        /// </summary>
        /// <param name="rsClient"></param>
        /// <param name="data"></param>
        /// <param name="isAsync">默认为异步调用</param>
        public void SendData(RegistryClient registryClient, CometMessageAction action, String data, Boolean isAsync = true)
        {
            try
            {
                CometMessage rm = new CometMessage()
                {
                    Action = action,
                    MessageBody = data,
                    IsAsync = isAsync
                };

                String messageData = XmlUtil.SaveXmlFromObj<CometMessage>(rm);
                Console.WriteLine("发送数据:{0}", messageData);

                Byte[] msg = Encoding.UTF8.GetBytes(messageData);
                registryClient.Socket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(SendCallback), registryClient);
            }
            catch (Exception ex)
            {
                XTrace.WriteLine("发送数据时发生异常:" + ex.ToString());
                lock (m_RegistryClients)
                {
                    m_RegistryClients.Remove(registryClient);
                    registryClient.Dispose();
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 向服务器发送数据
        /// </summary>
        /// <param name="message"></param>
        /// <param name="isAsync">如过为同步调用,则在回传的是后需要释放同步信号</param>
        public void SendData(CometMessageAction action, String message, Boolean isAsync = true)
        {
            if (m_SocketClient == null || !m_SocketClient.Connected)
            {
                throw new Exception("无法连接服务器!");
            }

            try
            {
                CometMessage regMessage = new CometMessage()
                {
                    Action = action,
                    IsAsync = isAsync,
                    ClientType = m_ClientType,
                    ClientVersion = ESBProxy.GetInstance().Version.Replace("MB.ESB.Core ", ""),
                    ProcessorID = Process.GetCurrentProcess().Id,
                    DotNetFramworkVersion = Environment.Version.ToString(),
                    OSVersion = Environment.OSVersion.ToString(),
                    MessageBody = message
                };

                String dataMessage = XmlUtil.SaveXmlFromObj<CometMessage>(regMessage);
                Console.WriteLine("发送数据:{0}", dataMessage);

                Byte[] data = Encoding.UTF8.GetBytes(dataMessage);
                m_SocketClient.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), m_SocketClient);
            }
            catch (Exception ex)
            {
                OnLostConnection(ex.ToString());
            }
        }