• 大小: 81KB
    文件类型: .rar
    金币: 2
    下载: 2 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签:

资源简介

用于局域网内的C#实现文件传输用于局域网内的C#实现文件传输

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;

namespace SocketClient
{
    public partial class Form1 : Form
    {
        IPAddress SendIP = null;
        Socket client;
        public Form1()
        {
            InitializeComponent();
        }

        private void Search_Click(object sender EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.FilePath.Text = this.openFileDialog1.FileName;
            }
        }
        /// 
        ///利用委托向RichTextBox中添加信息
        /// 

        /// 
        private delegate void AddMessageDelegate(string message);
        public void AddMessage(string message)
        {
            if (richTextBox1.InvokeRequired)
            {
                AddMessageDelegate d = AddMessage;
                richTextBox1.Invoke(d message);
            }
            else
            {
                richTextBox1.AppendText(message);

            }
        }

        private void Send_Click(object sender EventArgs e)
        {
            richTextBox1.Clear();
            try
            {
                SendIP = IPAddress.Parse(this.ReceiveIP.Text);
            }
            catch
            {
                MessageBox.Show(“IP地址有错误!“);
                return;
            }
            if (this.FilePath.Text.Length == 0)
            {
                MessageBox.Show(“请选择文件!“);
                return;
            }
            string Path = this.FilePath.Text;
            Thread SendFile = new Thread(StartSend);
            SendFile.Start(this.FilePath.Text);
            this.Send.Enabled = false;
        }
        public void StartSend(object Path)
        {
            string file = (string)Path.ToString();
            string message = null;
            try
            {
                //指向远程服务端节点
                IPEndPoint ipep = new IPEndPoint(SendIP 2011);
                //创建套接字   
                client = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
                //连接到发送端   
                client.Connect(ipep);
                //获得客户端节点对象   
                IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;
                FileInfo EzoneFile = new FileInfo(file);
                //打开文件流   
                FileStream EzoneStream = EzoneFile.OpenRead();
                //包的大小  
                int PacketSize = 50000;
                //包的数量   
                int PacketCount = (int)(EzoneStream.Length / ((long)PacketSize));
                //最后一个包的大小   
                int LastDataPacket = (int)(EzoneStream.Length - ((long)(PacketSize * PacketCount)));
   

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

     文件      24576  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient\bin\Debug\SocketClient.exe

     文件      32256  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient\bin\Debug\SocketClient.pdb

     文件       5632  2005-12-08 14:51  C#实现文件传输\SocketClient\SocketClient\bin\Debug\SocketClient.vshost.exe

     文件       5412  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient\Form1.cs

     文件       5941  2011-04-10 15:05  C#实现文件传输\SocketClient\SocketClient\Form1.Designer.cs

     文件       6017  2011-04-10 15:05  C#实现文件传输\SocketClient\SocketClient\Form1.resx

     文件        842  2011-04-10 15:05  C#实现文件传输\SocketClient\SocketClient\obj\Debug\SocketClient.csproj.GenerateResource.Cache

     文件      24576  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient\obj\Debug\SocketClient.exe

     文件        180  2011-04-10 15:05  C#实现文件传输\SocketClient\SocketClient\obj\Debug\SocketClient.Form1.resources

     文件      32256  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient\obj\Debug\SocketClient.pdb

     文件        180  2011-04-10 15:05  C#实现文件传输\SocketClient\SocketClient\obj\Debug\SocketClient.Properties.Resources.resources

     文件        303  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient\obj\SocketClient.csproj.FileList.txt

     文件        471  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient\Program.cs

     文件       1196  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient\Properties\AssemblyInfo.cs

     文件       2878  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient\Properties\Resources.Designer.cs

     文件       5612  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient\Properties\Resources.resx

     文件       1095  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient\Properties\Settings.Designer.cs

     文件        249  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient\Properties\Settings.settings

     文件       3271  2011-04-10 15:21  C#实现文件传输\SocketClient\SocketClient\SocketClient.csproj

     文件       1505  2011-04-10 15:21  C#实现文件传输\SocketClient\SocketClient\TransFile.cs

     文件        925  2011-04-10 15:00  C#实现文件传输\SocketClient\SocketClient.sln

    ..A..H.     12800  2011-04-10 15:26  C#实现文件传输\SocketClient\SocketClient.suo

     文件      20480  2011-04-13 23:39  C#实现文件传输\SocketServer\SocketServer\bin\Debug\SocketServer.exe

     文件      34304  2011-04-13 23:39  C#实现文件传输\SocketServer\SocketServer\bin\Debug\SocketServer.pdb

     文件       5632  2005-12-08 14:51  C#实现文件传输\SocketServer\SocketServer\bin\Debug\SocketServer.vshost.exe

     文件       4188  2011-04-10 15:26  C#实现文件传输\SocketServer\SocketServer\Form1.cs

     文件       2547  2011-04-10 14:47  C#实现文件传输\SocketServer\SocketServer\Form1.Designer.cs

     文件       5814  2011-04-10 14:47  C#实现文件传输\SocketServer\SocketServer\Form1.resx

     文件        842  2011-04-10 14:47  C#实现文件传输\SocketServer\SocketServer\obj\Debug\SocketServer.csproj.GenerateResource.Cache

     文件      20480  2011-04-13 23:39  C#实现文件传输\SocketServer\SocketServer\obj\Debug\SocketServer.exe

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

评论

共有 条评论

相关资源