コード例 #1
0
ファイル: SocketHelper.cs プロジェクト: romanu6891/fivemen
        /// <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;
        }
コード例 #2
0
ファイル: SocketHelper.cs プロジェクト: romanu6891/fivemen
        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)));

            }
        }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: TcpServerHelper.cs プロジェクト: romanu6891/fivemen
 /// <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;
 }
コード例 #5
0
ファイル: TcpServerHelper.cs プロジェクト: romanu6891/fivemen
 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);
 }
コード例 #6
0
ファイル: TcpServerHelper.cs プロジェクト: romanu6891/fivemen
        /// <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);
            }
        }
コード例 #7
0
ファイル: TcpServerHelper.cs プロジェクト: romanu6891/fivemen
 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 });
         }
     }
 }
コード例 #8
0
ファイル: TcpServerHelper.cs プロジェクト: romanu6891/fivemen
        /// <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);
            }
        }
コード例 #9
0
ファイル: TcpWatcherForm.cs プロジェクト: romanu6891/fivemen
 private void ParseMessage(MessageInfo info)
 {
     this.txtContext.AppendText("\r\n"+info.Data);
 }
コード例 #10
0
 private void MsgParse(MessageInfo info)
 {
     Console.WriteLine(info.Data);
        //this.txtAccept.AppendText("�������յ���Ϣ");
        //this.txtLog.AppendText("\r\n" + info.Data);
 }
コード例 #11
0
 public void NotifyMsg(MessageInfo info)
 {
     this.txtAccept.AppendText("\r\n收到" + info.Org.NickName + "服务器消息:\r\n\r\n" + info.Data);
 }
コード例 #12
0
 private void MsgParse(MessageInfo info)
 {
     Console.WriteLine(info.Data);
     //this.txtAccept.AppendText("服务器收到消息");
     //this.txtLog.AppendText("\r\n" + info.Data);
 }
コード例 #13
0
ファイル: TcpClientHelper.cs プロジェクト: romanu6891/fivemen
 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 });
         }
     }
 }
コード例 #14
0
ファイル: TcpClientHelper.cs プロジェクト: romanu6891/fivemen
 /// <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�ͻ������ӻ�û����ȷ�򿪣���ȷ��Ŀ��������ã�");
     }
 }
コード例 #15
0
ファイル: TcpBase.cs プロジェクト: romanu6891/fivemen
 /// <summary>
 /// �������̳еķ�������������һЩ�ڲ���Ϣ���ⲿ��Ϣ��msghandle����
 /// </summary>
 /// <param name="info">��Ϣ����</param>
 /// <param name="client">�ͻ��˶���</param>
 public abstract void ParseMessage(MessageInfo info,TcpClient client);
コード例 #16
0
ファイル: TcpBase.cs プロジェクト: marcellus/fivemen
 /// <summary>
 /// 子类必须继承的方法,用来处理一些内部消息,外部消息供msghandle处理
 /// </summary>
 /// <param name="info">消息内容</param>
 /// <param name="client">客户端对象</param>
 public abstract void ParseMessage(MessageInfo info, TcpClient client);
コード例 #17
0
 public void NotifyMsg(MessageInfo info)
 {
     this.txtAccept.AppendText("\r\n�յ�" + info.Org.NickName + "��������Ϣ��\r\n\r\n" + info.Data);
 }