資源簡介
用于局域網內的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個文件信息
評論
共有 條評論