/// <summary>
 /// ��Է�UDP�˿ڷ�����������
 /// </summary>
 private void UdpHandshake()
 {
     try
     {
         msgFile msg = new msgFile();
         if (!UdpHandshakeInfoClass)//�������������
         {
             msg.InfoClass = (byte)ProtocolFileTransmit.HandshakeLAN;
             this.sockUDP1.Send(this._OppositeUserInfo.LocalIP, this.OppositeUDPPort, msg.getBytes());
         }
         else if (UdpHandshakeInfoClass)//�������������
         {
             msg.InfoClass = (byte)ProtocolFileTransmit.HandshakeWAN;
             this.sockUDP1.Send(this._OppositeUserInfo.IP, this.OppositeUDPPort, msg.getBytes());
         }
     }
     catch { }
 }
        private void DataArrival(msgFile msg, NatClass netClass, System.Net.IPAddress Ip, int Port)
        {
            switch (msg.InfoClass)
            {
                case (byte)ProtocolFileTransmit.GetFileTransmitProxyID://����Լ��ӷ������ϻ����ת����ID
                    {
                        this.serverSelfID = msg.SendID;
                        if (this.serverOppositeID != -1)//����Ƿ��ͷ������ת����ID������߶Է���ʼ�ս��ļ�
                        {
                            this.netClass = NetCommunicationClass.TCP;//��ʶ��ǰͨ��Э��ΪTCP
                            //this._mtu = 1200;//�����������ļ�ʱ����MTUֵ����Ϊ1200ʹ·���������ǽת������
                            msg.InfoClass = (byte)ProtocolFileTransmit.BeginTransmit;
                            msg.SendID = this.serverSelfID;
                            msg.RecID = this.serverOppositeID;
                            this.sendData(msg);
                        }
                        else if (this.getFileProxyID != null)//����ǽ��շ��򴥷������ת����ID��֮�Է�
                            this.getFileProxyID(this, this.serverSelfID);
                    }
                    break;
                case (byte)ProtocolFileTransmit.FileTransmit://����ļ���������
                    {
                        //Calculate.WirteLog("�����ļ����Է�");
                        this.sendFile((int)msg.pSendPos);//�����ļ����Է�
                    }
                    break;
                case (byte)ProtocolFileTransmit.GetFileBlock :// ��öԷ�������ļ����ݰ�
                    {
                        //Calculate.WirteLog("�յ��ļ�����");
                        this.ReceivedFileBlock(msg);//�Է������ļ����ݹ���,�������ݵ��ļ�
                    }
                    break;
                case (byte)ProtocolFileTransmit.BeginTransmit://�����Ѿ��������Է�Ҫ��ʼ�����ļ�
                    {
                        this.serverOppositeID = msg.SendID;//��öԷ�ID
                        if (netClass == NatClass.Tcp)//�����TCPͨ��
                        {
                            this.netClass = NetCommunicationClass.TCP;//����TCPЭ�鴫���ļ�
                        }
                        else
                        {
                            this.netClass = NetCommunicationClass.WanNoProxyUDP;//����UDPЭ�鴫��
                        }

                        if (this.fileTransmitConnected != null)//����ͨ�ųɹ��¼������˳�ͨ�Ų���
                            this.fileTransmitConnected(this, this.netClass);

                        if (!this.IsSendState)//����ļ���û�п�ʼ���ͣ�����
                            this.sendRequestGetFileData();//�����ļ����Է�
                        //Calculate.WirteLog("�����Ѿ��������Է�Ҫ��ʼ�����ļ�");
                    }
                    break;
                case (byte)ProtocolFileTransmit.FileTranstmitOver ://�ļ��������
                    {
                        this.onFileTransmitted();
                    }
                    break;

                case (byte)ProtocolFileTransmit.HandshakeLAN://�յ��Է�������UDP��������
                    {
                        this._OppositeUserInfo.LocalIP = Ip;//�������öԷ��ľ�����IP
                        this.OppositeUDPPort = Port;//�������öԷ��ľ�����UDP�˿�
                        msg.InfoClass =(byte)ProtocolFileTransmit.IsOppositeRecSelfLanUDPData;//���߶Է��յ�����������Ϣ
                        this.sockUDP1.Send(this._OppositeUserInfo.LocalIP, this.OppositeUDPPort, msg.getBytes());
                        //Calculate.WirteLog(this._IsSend.ToString()+ "�յ��Է�������UDP��������:"+ Ip.ToString() +":"+ Port.ToString());
                    }
                    break;
                case (byte)ProtocolFileTransmit.IsOppositeRecSelfLanUDPData://�Է��յ��Լ����͵ľ�����UDP��������
                    {
                        this.netClass = NetCommunicationClass.LanUDP;//��ʶ��Է�����������ͨ�ųɹ�
                       if (this._IsSend)//����Ƿ����ļ���һ�����ҶԷ���֮�յ��Լ����������ݣ���ͨ��ͨ����ͨ
                       {
                           //this._mtu = 1400;//�����������ļ�ʱ����MTUֵ����Ϊ5120��5k������ٶ�
                           msg.InfoClass = (byte)ProtocolFileTransmit.BeginTransmit;
                           msg.SendID = 0;
                           this.sendData(msg);//���߶Է���ʼ�����ļ�
                       }
                       //Calculate.WirteLog(Ip.ToString() + ":" + Port.ToString() + "�Է��յ��Լ����͵ľ�����UDP��������" + this._IsSend.ToString());
                    }
                    break;

                case (byte)ProtocolFileTransmit.HandshakeWAN ://�յ��Է�������UDP��������
                    {
                        this._OppositeUserInfo.IP = Ip;//�������öԷ��Ĺ�����IP
                        this.OppositeUDPPort = Port;//�������öԷ��Ĺ�����UDP�˿�
                        msg.InfoClass = (byte)ProtocolFileTransmit.IsOppositeRecSelfWanUDPData ;//���߶Է��յ�����������Ϣ
                        this.sockUDP1.Send(this._OppositeUserInfo.IP, this.OppositeUDPPort, msg.getBytes());
                        //Calculate.WirteLog(this._IsSend.ToString()+ "�յ��Է�������UDP��������:"+ Ip.ToString() +":"+ Port.ToString());
                    }
                    break;
                case (byte)ProtocolFileTransmit.IsOppositeRecSelfWanUDPData://�Է��յ��Լ����͵ľ�����UDP��������
                    {
                        this.netClass = NetCommunicationClass.WanNoProxyUDP;//��ʶ��Է�����������ֱ��ͨ�ųɹ�
                        if (this._IsSend)//����Ƿ����ļ���һ�����ҶԷ���֮�յ��Լ����������ݣ���ͨ��ͨ����ͨ
                        {
                            //this._mtu = 1200;//�����������ļ�ʱ����MTUֵ����Ϊ1200��1k�ٶ�
                            msg.InfoClass = (byte)ProtocolFileTransmit.BeginTransmit;
                            msg.SendID = 0;
                            this.sendData(msg);//���߶Է���ʼ�����ļ�
                        }
                        //Calculate.WirteLog(Ip.ToString() + ":" + Port.ToString() + "�Է��յ��Լ����͵ľ�����UDP��������" + this._IsSend.ToString());
                    }
                    break;

                case (byte)ProtocolFileTransmit.GetUDPWANInfo://��÷��������ص��ļ������׽��ֹ�����UDP�˿�
                    {
                        this.selfUDPPort=msg.SendID;//�������öԷ��Ĺ�����UDP�˿�
                        if (!this.IsGetWanUDP && this.fileTransmitGetUDPPort != null)
                        {
                            this.IsGetWanUDP = true;//��ʶ�Ѿ�������WAN UDP�˿ڻ�ȡ�¼�
                            this.fileTransmitGetUDPPort(this, this.selfUDPPort, true);
                        }
                        //Calculate.WirteLog(this._IsSend.ToString() + "��÷��������ص��ļ������׽��ֹ�����UDP�˿�:" + this.selfUDPPort);
                    }
                    break;

            }
        }
 /// <summary>
 /// sockUDP �����ļ�����
 /// </summary>
 /// <param name="msg">�ļ���Ϣ</param>
 private void sendData(msgFile msg)
 {
     try
     {
         if (this.netClass == NetCommunicationClass.LanUDP)//����Ǿ�����ͨ��
             this.sockUDP1.Send(this._OppositeUserInfo.LocalIP,this.OppositeUDPPort, msg.getBytes());//����UDP�������ݵ��Է�������IP��˿�
         else if (this.netClass == NetCommunicationClass.WanNoProxyUDP)//����ǹ�����ֱ��ͨ��
             this.sockUDP1.Send(this._OppositeUserInfo.IP, this.OppositeUDPPort, msg.getBytes());//����UDP�������ݵ��Է�������IP��˿�
         //else if (this.netClass == NetCommunicationClass.WanProxyUDP)//����ǹ�������������תͨ��
         //    this.sockUDP1.Send(this._serverIp, this._serverUDPPort, msg.getBytes());//����UDP�������ݵ���������תIP��˿�
         else if (this.netClass == NetCommunicationClass.TCP)
             this.asyncTCPClient1.SendData(msg.getBytes());//����TCP��������
     }
     catch
     { }
 }
 private void asyncTCPClient1_OnConnected(object sender,  SockEventArgs  e)
 {
     //IMLibrary.Calculate.WirteLog("������");
        msgFile msg = new msgFile((byte)ProtocolFileTransmit.GetFileTransmitProxyID, -1, -1, 0, new byte[1]);
     this.asyncTCPClient1.SendData(msg.getBytes());//�������������ת����ID��
 }