• 大小: 393KB
    文件类型: .zip
    金币: 2
    下载: 2 次
    发布日期: 2021-05-19
  • 语言: C#
  • 标签: C#  UDP  文件  传输  

资源简介

基于C#的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;
                        }));
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-12 10:33  C#文件传输\
     目录           0  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\
     文件        6004  2009-08-02 17:45  C#文件传输\ReceiveFileDemo\Form1.Designer.cs
     文件        6853  2009-08-02 18:02  C#文件传输\ReceiveFileDemo\Form1.cs
     文件        5814  2009-08-02 17:45  C#文件传输\ReceiveFileDemo\Form1.resx
     文件         474  2009-07-28 16:18  C#文件传输\ReceiveFileDemo\Program.cs
     目录           0  2009-08-02 13:02  C#文件传输\ReceiveFileDemo\Properties\
     文件        1214  2009-07-28 16:18  C#文件传输\ReceiveFileDemo\Properties\AssemblyInfo.cs
     文件        2870  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\Properties\Resources.Designer.cs
     文件        5612  2009-07-28 16:18  C#文件传输\ReceiveFileDemo\Properties\Resources.resx
     文件        1115  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\Properties\Settings.Designer.cs
     文件         249  2009-07-28 16:18  C#文件传输\ReceiveFileDemo\Properties\Settings.settings
     文件        5261  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\ReceiveFileDemo.csproj
     文件         452  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\ReceiveFileDemo.csproj.user
     目录           0  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\bin\
     目录           0  2018-10-22 09:33  C#文件传输\ReceiveFileDemo\bin\Debug\
     文件       14848  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.exe
     文件       42496  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.pdb
     文件       11608  2018-10-16 09:08  C#文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.vshost.exe
     文件         490  2018-04-12 07:35  C#文件传输\ReceiveFileDemo\bin\Debug\ReceiveFileDemo.vshost.exe.manifest
     文件       35840  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\bin\Debug\UdpSendFile.dll
     文件      179712  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\bin\Debug\UdpSendFile.pdb
     目录           0  2018-10-22 09:33  C#文件传输\ReceiveFileDemo\bin\Release\
     目录           0  2009-08-02 13:02  C#文件传输\ReceiveFileDemo\obj\
     目录           0  2018-10-18 11:51  C#文件传输\ReceiveFileDemo\obj\Debug\
     文件        1229  2018-10-18 11:51  C#文件传输\ReceiveFileDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        5548  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         180  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.Form1.resources
     文件         180  2018-10-12 11:20  C#文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.Properties.Resources.resources
     文件        2280  2018-10-16 09:08  C#文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.csproj.FileListAbsolute.txt
     文件         902  2018-10-12 10:33  C#文件传输\ReceiveFileDemo\obj\Debug\ReceiveFileDemo.csproj.GenerateResource.Cache
............此处省略108个文件信息

评论

共有 条评论