示例#1
0
        private void UdpPeerReceiveData(object sender, ReceiveDataEventArgs e)
        {
            SendCell cell = new SendCell();
            cell.FromBuffer(e.Buffer);
            switch (cell.MessageID)
            {
                case (int)Command.ResponeSendFile:
                    lock (SendFileOutTimeLock)
                    {
                        ResponeTraFransfersFile item = (ResponeTraFransfersFile)cell.Data;
                        OnResponeSendFile(item);//同意接收文件
                        try
                        {

                            if (SendFileManagerList.ContainsKey(item.MD5))
                            {
                                SendFileManagerList[item.MD5].SendFileOutTime = -1;
                            }
                            else
                            {
                                Send((int)Command.RequestCancelSendFile, item.MD5);
                            }
                        }
                        catch (Exception)
                        {
                            Send((int)Command.RequestCancelSendFile, item.MD5);
                        }
                    }
                    break;
                case (int)Command.ResponeSendFilePack:
                    ResponeSendFilePack((ResponeTraFransfersFile)cell.Data);
                    break;
                case (int)Command.RequestCancelReceiveFile:
                    RequestCancelReceiveFile(cell.Data.ToString());
                    break;
            }
        }
示例#2
0
 /// <summary>
 /// udp接收事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void UdpPeerReceiveData(object sender, ReceiveDataEventArgs e)
 {
     SendCell cell = new SendCell();
     cell.FromBuffer(e.Buffer);
     switch (cell.MessageID)
     {
         case (int)Command.RequestSendFile:
             OnStartRecieve((TraFransfersFileStart)cell.Data, e.RemoteIP);
             break;
         case (int)Command.RequestSendFilePack:
             OnRecieveBuffer((TraFransfersFile)cell.Data, e.RemoteIP);
             break;
         case (int)Command.RequestCancelSendFile:
             OnRequestCancelSendFile(cell.Data.ToString(), e.RemoteIP);
             break;
     }
 }