资源简介

该代码实现,文件的传输是基于UDP协议 在要使用传输大的文件如视频 图片时很有参考价值 希望能帮助到大家

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CSharpWin;
using System.Diagnostics;

namespace ReceiveFileDemo
{
    public partial class Form1 : Form
    {
        private UdpReceiveFile receiveFile;

        public Form1()
        {
            InitializeComponent();
            linkLabel1.Click += delegate(object sender EventArgs e)
            {
               Process.Start(“www.csharpwin.com“);
            };
        }

        private void button1_Click(object sender EventArgs e)
        {
            receiveFile = new UdpReceiveFile(
                int.Parse(tbLocalPort.Text));
            //receiveFile.Log += new TraFransfersFileLogEventHandler(recieveFile_Log);
            receiveFile.RequestSendFile += 
                new RequestSendFileEventHandler(ReceiveFileRequestSendFile);
            receiveFile.FileReceiveBuffer +=
                new FileReceiveBufferEventHandler(ReceiveFileFileReceiveBuffer);
            receiveFile.FileReceiveComplete += 
                new FileReceiveEventHandler(FileReceiveComplete);
            receiveFile.Start();
            AppendLog(string.Format(
                “开始侦听,端口:{0}“ receiveFile.Port) false);
        }

        void FileReceiveComplete(object sender FileReceiveEventArgs e)
        {
            foreach (TraFransfersFileControl control in panelSend.Controls)
            {
                if (control.Tag.ToString() == e.ReceiveFileManager.MD5)
                {
                    BeginInvoke(new MethodInvoker(delegate()
                    {
                       panelSend.Controls.Remove(control);
                       control.Dispose();
                    }));
                    break;
                }
            }
            AppendLog(string.Format(
                “文件 {0} 接收完成,MD5 校验: {1}。“
                e.ReceiveFileManager.FileName e.ReceiveFileManager.Success) true);
        }

        void ReceiveFileFileReceiveBuffer(object sender FileReceiveBufferEventArgs e)
        {
            TraFransfersFileControl control =
                e.ReceiveFileManager.Tag as TraFransfersFileControl;
            if (control != null)
            {
                BeginInvoke(new MethodInvoker(delegate()
                {
                    control.TraFransfersSize += e.Size;
                }));
            }
            else
            {
                foreach (TraFransfersFileControl control1 in panelSend.Controls)
                {
                    if (control1.Tag.ToString() == e.ReceiveFileManager.MD5)
                    {
                        e.ReceiveFileManager.Tag = control1;
                        BeginInvoke(new MethodInvoker(delegate()
                        {
                            control1.TraFransfersSize += e.Size;
                        }));
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      14848  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.exe

     文件      42496  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.pdb

     文件      11608  2018-10-16 09:08  基于UDP大文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.vshost.exe

     文件        490  2018-04-12 07:35  基于UDP大文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.vshost.exe.manifest

     文件      35840  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\bin\Debug\UdpSendFile.dll

     文件     179712  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\bin\Debug\UdpSendFile.pdb

     文件       6853  2009-08-02 18:02  基于UDP大文件传输\ReceiveFileDemo\Form1.cs

     文件       6004  2009-08-02 17:45  基于UDP大文件传输\ReceiveFileDemo\Form1.Designer.cs

     文件       5814  2009-08-02 17:45  基于UDP大文件传输\ReceiveFileDemo\Form1.resx

     文件       1229  2019-07-09 14:18  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6314  2019-07-09 14:17  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2280  2018-10-16 09:08  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.csproj.FileListAbsolute.txt

     文件        902  2018-10-12 10:33  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.csproj.GenerateResource.Cache

     文件       9794  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.csprojResolveAssemblyReference.cache

     文件      14848  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.exe

     文件        180  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.Form1.resources

     文件      42496  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.pdb

     文件        180  2018-10-12 11:20  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.Properties.Resources.resources

     文件       4608  2018-10-12 10:33  基于UDP大文件传输\ReceiveFileDemo\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        378  2009-08-02 18:44  基于UDP大文件传输\ReceiveFileDemo\obj\ReceiveFileDemo.csproj.FileList.txt

     文件        474  2009-07-28 16:18  基于UDP大文件传输\ReceiveFileDemo\Program.cs

     文件       1214  2009-07-28 16:18  基于UDP大文件传输\ReceiveFileDemo\Properties\AssemblyInfo.cs

     文件       2870  2018-10-12 10:33  基于UDP大文件传输\ReceiveFileDemo\Properties\Resources.Designer.cs

     文件       5612  2009-07-28 16:18  基于UDP大文件传输\ReceiveFileDemo\Properties\Resources.resx

     文件       1115  2018-10-12 10:33  基于UDP大文件传输\ReceiveFileDemo\Properties\Settings.Designer.cs

     文件        249  2009-07-28 16:18  基于UDP大文件传输\ReceiveFileDemo\Properties\Settings.settings

     文件       5261  2018-10-12 10:33  基于UDP大文件传输\ReceiveFileDemo\ReceiveFileDemo.csproj

     文件        452  2018-10-12 10:33  基于UDP大文件传输\ReceiveFileDemo\ReceiveFileDemo.csproj.user

     文件      46592  2009-08-02 17:52  基于UDP大文件传输\Thumbs.db

     文件      35840  2018-10-12 11:20  基于UDP大文件传输\UdpSendFile\bin\Debug\UdpSendFile.dll

............此处省略113个文件信息

评论

共有 条评论