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; } }
private void Connected(object sender, NetCommunicationClass netClass) { if (this.fileTransmitConnected != null) this.fileTransmitConnected(sender, netClass); }
private void p2pFileTransmit1_fileTransmitConnected(object sender, NetCommunicationClass netClass) { try { ConnectedDelegate d = new ConnectedDelegate(Connected); this.BeginInvoke(d, sender, netClass); } catch (Exception) { } }
/// <summary> /// 文件传输组件事件:发送与接收双方的文件传输组件中的UDP或TCP套接字之间已经联接 /// </summary> /// <param name="sender">文件传输组件对像</param> /// <param name="netCommuctionClass">联接方式</param> private void fSend_fileTransmitConnected(object sender, NetCommunicationClass netCommuctionClass) { if (netCommuctionClass == NetCommunicationClass.LanUDP) //this.infoMessage1.showMsg("已与对方建立了UDP联接."); AppendSystemRtf("已与对方建立了UDP联接."); //else if (netCommuctionClass == NetCommunicationClass.WanNoProxyUDP) //this.infoMessage1.showMsg("已与对方建立了UDP联接."); //AppendSystemRtf("已与对方建立了代理UDP联接."); else if (netCommuctionClass == NetCommunicationClass.TCP) //this.infoMessage1.showMsg("已与对方建立了TCP中转联接."); AppendSystemRtf("已与对方建立了TCP中转联接."); else if (netCommuctionClass == NetCommunicationClass.WanProxyUDP) //this.infoMessage1.showMsg("已与对方建立了UDP中转联接."); AppendSystemRtf("已与对方建立了UDP中转联接."); else if (netCommuctionClass == NetCommunicationClass.None) { AppendSystemRtf("无法与对方建立文件传输通道,取消文件传输!"); } }