Exemple #1
0
        /// <summary>
        /// ��TcpClient��д��һ��MessageInfo����
        /// </summary>
        /// <param name="client">TcpClient����</param>
        /// <param name="info">MessageInfo����</param>
        public void WriteData(TcpClient client,MessageInfo info)
        {
            if (client!=null&&client.Connected)
            {
                string msg=SecurityFactory.GetSecurity().Encrypt(SerializeHelper.SerializeToXml(info));
                byte[] myWriteBuffer=System.Text.Encoding.UTF8.GetBytes(msg);
                NetworkStream stream=client.GetStream();
                bool flag=false;
                int i = 0;
                while (!flag)
                {
                    if (i + 1024 <= myWriteBuffer.Length)
                    {
                        stream.Write(myWriteBuffer, i, 1024);
                    }
                    else
                    {
                        stream.Write(myWriteBuffer, i, myWriteBuffer.Length - i);
                        flag = true;
                    }
                    stream.Flush();
                    i += 1024;
                }

            }
            //return string.Empty;
        }
Exemple #2
0
        public void ReadFinish(IAsyncResult iar)
        {
            if(log.IsDebugEnabled)
                log.Debug("�߳�"+System.Threading.Thread.CurrentThread.ManagedThreadId+"��ʼ�������ݻص�");
            NetworkStream stream = (NetworkStream)iar.AsyncState;
            int real=stream.EndRead(iar);
            if (real == 0)
            {

            }
            else
            {
                //info = new MessageInfo();
                info =(MessageInfo)SerializeHelper.DeserializeFromXml(typeof(MessageInfo),
                    SecurityFactory.GetSecurity().Decrypt(System.Text.Encoding.UTF8.GetString(buffers, 0, real)));

            }
        }
 public static void Send(MessageInfo info)
 {
     ClientConfig config = ClientConfig.GetConfig();
     if (config == null)
     {
         MessageBoxHelper.Show("�������÷��������ӣ�");
         return;
     }
     if (clientHelper == null)
     {
         if (logHandle == null)
         {
             MessageBoxHelper.Show("����������־�����ί�У�");
             return;
         }
         clientHelper = new TcpClientHelper(null,logHandle);
         //clientHelper.Start();
     }
     if (!clientHelper.IsStarted)
     {
         clientHelper.Start();
     }
     clientHelper.Send(info);
 }
 /// <summary>
 /// ����Ϣ�л�ȡһ��Customer����
 /// </summary>
 /// <param name="info">��Ϣ����</param>
 /// <returns>Customer����</returns>
 private Customer CopyFromMessageInfo(MessageInfo info)
 {
     Customer customer = new Customer();
     customer.Org = info.Org;
     customer.Sender = info.Sender;
     customer.Version = info.Version;
     return customer;
 }
 public void SendToClient(Customer customer, MessageInfo info)
 {
     string xml = SerializeHelper.SerializeToXml(info);
     byte[] tmp = System.Text.Encoding.UTF8.GetBytes(SecurityFactory.GetSecurity().Encrypt(xml));
     customer.Client.BeginSend(tmp, 0, tmp.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), customer.Client);
 }
        /// <summary>
        /// �������ͻ�����Ϣ
        /// </summary>
        /// <param name="info">��Ϣ����</param>
        /// <param name="index">�ͻ�����</param>
        public void Send(MessageInfo info,int key)
        {
            Customer customer= this.clients[key]  as Customer;
            if(customer!=null)
            {

                this.Log("������֪ͨ�ͻ���" + customer.Org.FullName);
                this.SendToClient(customer, info);
                //SocketHelper.WriteData(customer.Client, info);
            }
        }
 public override void ParseMessage(MessageInfo info,TcpClient client)
 {
     /*
      if (info == null)
         {
             this.Log("��ȡ��½�û���ϢΪ�գ�");
             System.Threading.Thread.Sleep(200);
         }
         else if (info.Data == TcpComand.Login)
         {
             this.Log("��ȡ����½�û���Ϣ��");
             Customer customer = new Customer();
             customer.Org = info.Org;
             customer.Sender = info.Sender;
             customer.Version = info.Version;
             customer.Client = client;
             this.clients.Add(customer, customer);
             //flag = false;
         }
         else
         {
             this.Parse();
         }
      */
     if (info.Type == MessageType.String && info.Data == TcpComand.Bye)
     {
         this.Log("�������յ��Ͽ�������");
         client.Close();
         this.clients.Remove((int)client.Client.Handle);
         this.Log("�������ɹ��Ͽ�����");
         this.Log("���������пͻ�����" + this.clients.Count);
     }
     if (info.Type == MessageType.String && info.Data == TcpComand.Login)
     {
         this.Log("��������ȡ����½�û���Ϣ��");
         Customer customer = new Customer();
         customer.Org = info.Org;
         customer.Sender = info.Sender;
         customer.Version = info.Version;
         customer.Client = client.Client;
         this.clients.Add((int)customer.Client.Handle, customer);
         this.Log("���������пͻ�����" + this.clients.Count);
     }
     else
     {
         if (this.Parent != null)
         {
             this.Parent.Invoke(this.MsgHandle, new object[] { info });
         }
     }
 }
        /// <summary>
        /// ֪ͨȫ����������ӵ�֪ͨ
        /// </summary>
        /// <param name="info">��Ϣ����</param>
        public void Notify(MessageInfo info)
        {
            Customer customer = null;

            System.Collections.IDictionaryEnumerator enumerator = this.clients.GetEnumerator();
            while (enumerator.MoveNext())
            {
                customer = enumerator.Value as Customer;
                this.Log("������֪ͨ�ͻ���" + customer.Org.FullName);
                this.SendToClient(customer, info);
            }
        }
Exemple #9
0
 private void ParseMessage(MessageInfo info)
 {
     this.txtContext.AppendText("\r\n"+info.Data);
 }
 private void MsgParse(MessageInfo info)
 {
     Console.WriteLine(info.Data);
        //this.txtAccept.AppendText("�������յ���Ϣ");
        //this.txtLog.AppendText("\r\n" + info.Data);
 }
Exemple #11
0
 public void NotifyMsg(MessageInfo info)
 {
     this.txtAccept.AppendText("\r\n收到" + info.Org.NickName + "服务器消息:\r\n\r\n" + info.Data);
 }
Exemple #12
0
 private void MsgParse(MessageInfo info)
 {
     Console.WriteLine(info.Data);
     //this.txtAccept.AppendText("服务器收到消息");
     //this.txtLog.AppendText("\r\n" + info.Data);
 }
Exemple #13
0
 public override void ParseMessage(MessageInfo info,TcpClient client)
 {
     if (info.Type ==MessageType.String&&info.Data==TcpComand.Bye)
     {
         this.Stop();
     }
     else
     {
         if (this.Parent != null)
         {
             this.Parent.Invoke(this.MsgHandle, new object[] { info });
         }
     }
 }
Exemple #14
0
 /// <summary>
 /// ����һ����Ϣ����
 /// </summary>
 /// <param name="info">��Ϣ����</param>
 public void Send(MessageInfo info)
 {
     if (info.Data == TcpComand.Login)
     {
         isLogMsg = true;
     }
     else
     {
         isLogMsg = false;
     }
     //locked.WaitOne();
     if (this.IsStarted)
     {
         string xml = SerializeHelper.SerializeToXml(info);
         byte[] tmp = System.Text.Encoding.UTF8.GetBytes(
             SecurityFactory.GetSecurity().Encrypt(xml));
         try
         {
             this.tcpClient.Client.BeginSend(tmp, 0, tmp.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), this.tcpClient.Client);
         }
         catch (Exception ex)
         {
             this.Stop();
             this.Log("FailԶ�������ѶϿ�");
         }
         //SocketHelper.WriteData(this.tcpClient,info);
     }
     else
     {
         this.Log("Fail�ͻ������ӻ�û����ȷ�򿪣���ȷ��Ŀ��������ã�");
     }
 }
Exemple #15
0
 /// <summary>
 /// �������̳еķ�������������һЩ�ڲ���Ϣ���ⲿ��Ϣ��msghandle����
 /// </summary>
 /// <param name="info">��Ϣ����</param>
 /// <param name="client">�ͻ��˶���</param>
 public abstract void ParseMessage(MessageInfo info,TcpClient client);
Exemple #16
0
 /// <summary>
 /// 子类必须继承的方法,用来处理一些内部消息,外部消息供msghandle处理
 /// </summary>
 /// <param name="info">消息内容</param>
 /// <param name="client">客户端对象</param>
 public abstract void ParseMessage(MessageInfo info, TcpClient client);
 public void NotifyMsg(MessageInfo info)
 {
     this.txtAccept.AppendText("\r\n�յ�" + info.Org.NickName + "��������Ϣ��\r\n\r\n" + info.Data);
 }