////////////////////////////////////////////////////////////////////////////////
//Author: stardicky //
//E-mail: [email protected] //
//QQNumber: 9531511 //
//CompanyName: Ezone International //
//Class: HBS-0308 //
//title: 亿众国际点对点文件传输程序 //
////////////////////////////////////////////////////////////////////////////////
//////////////////////////Begin-亿众国际发送端//////////////////////////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace 亿众国际发送端
{
///
1<summary>
2/// Form1 的摘要说明。
3/// </summary>
public class EzoneSend : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox textBox9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox textBox10;
///
1<summary>
2/// 必需的设计器变量。
3/// </summary>
private System.ComponentModel.Container components = null;
public EzoneSend()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
1<summary>
2/// 清理所有正在使用的资源。
3/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
1<summary>
2/// 设计器支持所需的方法 - 不要使用代码编辑器修改
3/// 此方法的内容。
4/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.textBox7 = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.textBox8 = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label();
this.textBox9 = new System.Windows.Forms.TextBox();
this.label11 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.textBox10 = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(416, 96);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "文件信息";
//
// openFileDialog1
//
this.openFileDialog1.Filter = "所有文件|.";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 16);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(304, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(320, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 23);
this.button1.TabIndex = 1;
this.button1.Text = "浏览";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 16);
this.label1.TabIndex = 2;
this.label1.Text = "文件名:";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(80, 40);
this.textBox2.Name = "textBox2";
this.textBox2.ReadOnly = true;
this.textBox2.Size = new System.Drawing.Size(232, 21);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 16);
this.label2.TabIndex = 4;
this.label2.Text = "文件大小:";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(80, 64);
this.textBox3.Name = "textBox3";
this.textBox3.ReadOnly = true;
this.textBox3.Size = new System.Drawing.Size(136, 21);
this.textBox3.TabIndex = 3;
this.textBox3.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBox6);
this.groupBox2.Controls.Add(this.textBox5);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.textBox4);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Location = new System.Drawing.Point(0, 96);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(416, 72);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "系统设置";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 16);
this.label3.TabIndex = 0;
this.label3.Text = "本机IP地址:";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(96, 16);
this.textBox4.Name = "textBox4";
this.textBox4.ReadOnly = true;
this.textBox4.Size = new System.Drawing.Size(144, 21);
this.textBox4.TabIndex = 1;
this.textBox4.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(256, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(100, 16);
this.label4.TabIndex = 2;
this.label4.Text = "传输端口:";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(320, 16);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(80, 21);
this.textBox5.TabIndex = 3;
this.textBox5.Text = "8888";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.textBox8);
this.groupBox3.Controls.Add(this.textBox9);
this.groupBox3.Controls.Add(this.textBox7);
this.groupBox3.Controls.Add(this.progressBar1);
this.groupBox3.Controls.Add(this.label7);
this.groupBox3.Controls.Add(this.label8);
this.groupBox3.Controls.Add(this.label10);
this.groupBox3.Controls.Add(this.label11);
this.groupBox3.Controls.Add(this.label12);
this.groupBox3.Controls.Add(this.textBox10);
this.groupBox3.Location = new System.Drawing.Point(0, 168);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(416, 168);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "状态信息";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.button2);
this.groupBox4.Location = new System.Drawing.Point(0, 336);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(416, 48);
this.groupBox4.TabIndex = 3;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "系统控制";
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 16);
this.button2.Name = "button2";
this.button2.TabIndex = 0;
this.button2.Text = "开始发送";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 48);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(88, 16);
this.label5.TabIndex = 2;
this.label5.Text = "包的大小:";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(96, 40);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(72, 21);
this.textBox6.TabIndex = 3;
this.textBox6.Text = "50000";
//
// label6
//
this.label6.Location = new System.Drawing.Point(224, 72);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(96, 16);
this.label6.TabIndex = 2;
this.label6.Text = "(单位:字节)";
//
// label7
//
this.label7.Location = new System.Drawing.Point(32, 24);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(96, 16);
this.label7.TabIndex = 2;
this.label7.Text = "接收端IP地址:";
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(8, 136);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(400, 23);
this.progressBar1.Step = 1;
this.progressBar1.TabIndex = 3;
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(120, 16);
this.textBox7.Name = "textBox7";
this.textBox7.ReadOnly = true;
this.textBox7.Size = new System.Drawing.Size(160, 21);
this.textBox7.TabIndex = 1;
this.textBox7.Text = "";
//
// label8
//
this.label8.Location = new System.Drawing.Point(40, 48);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(80, 16);
this.label8.TabIndex = 2;
this.label8.Text = "包的总数量:";
//
// label9
//
this.label9.Location = new System.Drawing.Point(176, 48);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(224, 16);
this.label9.TabIndex = 2;
this.label9.Text = "(范围:10000 - 60000 单位:字节)";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(120, 40);
this.textBox8.Name = "textBox8";
this.textBox8.ReadOnly = true;
this.textBox8.Size = new System.Drawing.Size(160, 21);
this.textBox8.TabIndex = 1;
this.textBox8.Text = "";
//
// label10
//
this.label10.Location = new System.Drawing.Point(8, 72);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(120, 16);
this.label10.TabIndex = 2;
this.label10.Text = "最后一个包的大小:";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(120, 64);
this.textBox9.Name = "textBox9";
this.textBox9.ReadOnly = true;
this.textBox9.Size = new System.Drawing.Size(80, 21);
this.textBox9.TabIndex = 1;
this.textBox9.Text = "";
//
// label11
//
this.label11.Location = new System.Drawing.Point(200, 72);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(96, 16);
this.label11.TabIndex = 2;
this.label11.Text = "(单位:字节)";
//
// label12
//
this.label12.Location = new System.Drawing.Point(16, 96);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(104, 16);
this.label12.TabIndex = 2;
this.label12.Text = "已发送包的数量:";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(120, 88);
this.textBox10.Name = "textBox10";
this.textBox10.ReadOnly = true;
this.textBox10.Size = new System.Drawing.Size(80, 21);
this.textBox10.TabIndex = 1;
this.textBox10.Text = "";
//
// EzoneSend
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(416, 389);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "EzoneSend";
this.Text = "亿众国际点对点文件传输软体发送端";
this.Load += new System.EventHandler(this.EzoneSend_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
1<summary>
2/// 应用程序的主入口点。
3/// </summary>
[STAThread]
static void Main()
{
Application.Run(new EzoneSend());
}
private void button1_Click(object sender, System.EventArgs e)
{
//选择要进行传输的文件
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
FileInfo EzoneFile=new FileInfo(this.openFileDialog1.FileName);
this.textBox1.Text=EzoneFile.FullName;
this.textBox2.Text=EzoneFile.Name;
this.textBox3.Text=EzoneFile.Length.ToString();
}
}
private void StartSend()
{
//创建一个文件对象
FileInfo EzoneFile=new FileInfo(this.textBox1.Text);
//打开文件流
FileStream EzoneStream=EzoneFile.OpenRead();
//包的大小
int PacketSize=int.Parse(this.textBox6.Text);
//包的数量
int PacketCount=(int)(EzoneStream.Length/((long)PacketSize));
this.textBox8.Text=PacketCount.ToString();
this.progressBar1.Maximum=PacketCount;
//最后一个包的大小
int LastDataPacket=(int)(EzoneStream.Length-((long)(PacketSize*PacketCount)));
this.textBox9.Text=LastDataPacket.ToString();
//创建一个网络端点
IPEndPoint ipep=new IPEndPoint(IPAddress.Any,int.Parse(this.textBox5.Text));
//创建一个套接字
Socket server=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
//绑定套接字到端口
server.Bind(ipep);
//开始侦听(并堵塞该线程)
server.Listen(10);
//确认连接
Socket client=server.Accept();
//获得客户端节点对象
IPEndPoint clientep=(IPEndPoint)client.RemoteEndPoint;
//获得客户端的IP地址
this.textBox7.Text=clientep.Address.ToString();
//发送[文件名]到客户端
CommonModule.EzoneModule.SendVarData(client,System.Text.Encoding.Unicode.GetBytes(EzoneFile.Name));
//发送[包的大小]到客户端
CommonModule.EzoneModule.SendVarData(client,System.Text.Encoding.Unicode.GetBytes(PacketSize.ToString()));
//发送[包的总数量]到客户端
CommonModule.EzoneModule.SendVarData(client,System.Text.Encoding.Unicode.GetBytes(PacketCount.ToString()));
//发送[最后一个包的大小]到客户端
CommonModule.EzoneModule.SendVarData(client,System.Text.Encoding.Unicode.GetBytes(LastDataPacket.ToString()));
//数据包
byte[] data=new byte[PacketSize];
//开始循环发送数据包
for(int i=0;i
1<packetcount;i++) <summary="" begin-亿众国际接收端="" button2_click(object="" byte[lastdatapacket];="" client.close();="" commonmodule.ezonemodule.sendvardata(client,data);="" data="new" e)="" end-亿众国际发送端="" ezonesend_load(object="" ezonestream.close();="" ezonestream.read(data,0,data.length);="" if(lastdatapacket!="0)" messagebox.show("文件传输完毕!");="" namespace="" private="" sender,="" server.close();="" system.collections;="" system.componentmodel;="" system.data;="" system.drawing;="" system.eventargs="" system.io;="" system.net.sockets;="" system.net;="" system.threading;="" system.windows.forms;="" system;="" tempthread="new" tempthread.start();="" this.button2.enabled="false;" this.progressbar1.performstep();="" this.progressbar1.value="this.progressBar1.Maximum;" this.textbox10.text="((int)(i+1)).ToString();" this.textbox4.text="Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();" thread="" thread(new="" threadstart(this.startsend));="" using="" void="" {="" }="" 亿众国际接收端="" 从文件流读取数据并填充数据包="" 关闭套接字="" 关闭文件流="" 发送数据包="" 如果还有多余的数据包,则应该发送完毕!="" 开启文件传输子线程="" 显示发送数据包的个数="" 获得本机的ip地址="" 进度条值的显示="">
2/// Form1 的摘要说明。
3///
4public class EzoneReceive : System.Windows.Forms.Form
5{
6private System.Windows.Forms.GroupBox groupBox1;
7private System.Windows.Forms.Button button1;
8private System.Windows.Forms.GroupBox groupBox3;
9private System.Windows.Forms.GroupBox groupBox2;
10private System.Windows.Forms.TextBox textBox5;
11private System.Windows.Forms.Label label4;
12private System.Windows.Forms.TextBox textBox4;
13private System.Windows.Forms.Label label3;
14private System.Windows.Forms.TextBox textBox1;
15private System.Windows.Forms.Label label1;
16private System.Windows.Forms.Label label2;
17private System.Windows.Forms.TextBox textBox2;
18private System.Windows.Forms.TextBox textBox8;
19private System.Windows.Forms.TextBox textBox9;
20private System.Windows.Forms.Label label8;
21private System.Windows.Forms.Label label10;
22private System.Windows.Forms.Label label11;
23private System.Windows.Forms.Label label12;
24private System.Windows.Forms.TextBox textBox10;
25private System.Windows.Forms.ProgressBar progressBar1;
26private System.Windows.Forms.TextBox textBox3;
27private System.Windows.Forms.Label label5;
28private System.Windows.Forms.Label label6;
29/// <summary>
30/// 必需的设计器变量。
31/// </summary>
32private System.ComponentModel.Container components = null;
33
34public EzoneReceive()
35{
36//
37// Windows 窗体设计器支持所必需的
38//
39InitializeComponent();
40
41//
42// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
43//
44}
45
46/// <summary>
47/// 清理所有正在使用的资源。
48/// </summary>
49protected override void Dispose( bool disposing )
50{
51if( disposing )
52{
53if (components != null)
54{
55components.Dispose();
56}
57}
58base.Dispose( disposing );
59}
60
61#region Windows 窗体设计器生成的代码
62/// <summary>
63/// 设计器支持所需的方法 - 不要使用代码编辑器修改
64/// 此方法的内容。
65/// </summary>
66private void InitializeComponent()
67{
68this.groupBox1 = new System.Windows.Forms.GroupBox();
69this.button1 = new System.Windows.Forms.Button();
70this.groupBox3 = new System.Windows.Forms.GroupBox();
71this.groupBox2 = new System.Windows.Forms.GroupBox();
72this.textBox5 = new System.Windows.Forms.TextBox();
73this.label4 = new System.Windows.Forms.Label();
74this.textBox4 = new System.Windows.Forms.TextBox();
75this.label3 = new System.Windows.Forms.Label();
76this.textBox1 = new System.Windows.Forms.TextBox();
77this.label1 = new System.Windows.Forms.Label();
78this.label2 = new System.Windows.Forms.Label();
79this.textBox2 = new System.Windows.Forms.TextBox();
80this.textBox8 = new System.Windows.Forms.TextBox();
81this.textBox9 = new System.Windows.Forms.TextBox();
82this.label8 = new System.Windows.Forms.Label();
83this.label10 = new System.Windows.Forms.Label();
84this.label11 = new System.Windows.Forms.Label();
85this.label12 = new System.Windows.Forms.Label();
86this.textBox10 = new System.Windows.Forms.TextBox();
87this.progressBar1 = new System.Windows.Forms.ProgressBar();
88this.textBox3 = new System.Windows.Forms.TextBox();
89this.label5 = new System.Windows.Forms.Label();
90this.label6 = new System.Windows.Forms.Label();
91this.groupBox1.SuspendLayout();
92this.groupBox3.SuspendLayout();
93this.groupBox2.SuspendLayout();
94this.SuspendLayout();
95//
96// groupBox1
97//
98this.groupBox1.Controls.Add(this.button1);
99this.groupBox1.Location = new System.Drawing.Point(0, 256);
100this.groupBox1.Name = "groupBox1";
101this.groupBox1.Size = new System.Drawing.Size(408, 48);
102this.groupBox1.TabIndex = 0;
103this.groupBox1.TabStop = false;
104this.groupBox1.Text = "系统控制";
105//
106// button1
107//
108this.button1.Location = new System.Drawing.Point(8, 16);
109this.button1.Name = "button1";
110this.button1.TabIndex = 0;
111this.button1.Text = "开始接收";
112this.button1.Click += new System.EventHandler(this.button1_Click);
113//
114// groupBox3
115//
116this.groupBox3.Controls.Add(this.progressBar1);
117this.groupBox3.Controls.Add(this.textBox8);
118this.groupBox3.Controls.Add(this.textBox9);
119this.groupBox3.Controls.Add(this.label8);
120this.groupBox3.Controls.Add(this.label10);
121this.groupBox3.Controls.Add(this.label11);
122this.groupBox3.Controls.Add(this.label12);
123this.groupBox3.Controls.Add(this.textBox10);
124this.groupBox3.Controls.Add(this.textBox2);
125this.groupBox3.Controls.Add(this.label2);
126this.groupBox3.Controls.Add(this.textBox3);
127this.groupBox3.Controls.Add(this.label5);
128this.groupBox3.Controls.Add(this.label6);
129this.groupBox3.Location = new System.Drawing.Point(0, 72);
130this.groupBox3.Name = "groupBox3";
131this.groupBox3.Size = new System.Drawing.Size(408, 184);
132this.groupBox3.TabIndex = 4;
133this.groupBox3.TabStop = false;
134this.groupBox3.Text = "状态信息";
135//
136// groupBox2
137//
138this.groupBox2.Controls.Add(this.textBox5);
139this.groupBox2.Controls.Add(this.label4);
140this.groupBox2.Controls.Add(this.textBox4);
141this.groupBox2.Controls.Add(this.label3);
142this.groupBox2.Controls.Add(this.textBox1);
143this.groupBox2.Controls.Add(this.label1);
144this.groupBox2.Location = new System.Drawing.Point(0, 0);
145this.groupBox2.Name = "groupBox2";
146this.groupBox2.Size = new System.Drawing.Size(408, 72);
147this.groupBox2.TabIndex = 3;
148this.groupBox2.TabStop = false;
149this.groupBox2.Text = "系统设置";
150//
151// textBox5
152//
153this.textBox5.Location = new System.Drawing.Point(320, 40);
154this.textBox5.Name = "textBox5";
155this.textBox5.Size = new System.Drawing.Size(80, 21);
156this.textBox5.TabIndex = 3;
157this.textBox5.Text = "8888";
158//
159// label4
160//
161this.label4.Location = new System.Drawing.Point(280, 48);
162this.label4.Name = "label4";
163this.label4.Size = new System.Drawing.Size(100, 16);
164this.label4.TabIndex = 2;
165this.label4.Text = "端口:";
166//
167// textBox4
168//
169this.textBox4.Location = new System.Drawing.Point(104, 16);
170this.textBox4.Name = "textBox4";
171this.textBox4.ReadOnly = true;
172this.textBox4.Size = new System.Drawing.Size(160, 21);
173this.textBox4.TabIndex = 1;
174this.textBox4.Text = "";
175//
176// label3
177//
178this.label3.Location = new System.Drawing.Point(16, 24);
179this.label3.Name = "label3";
180this.label3.Size = new System.Drawing.Size(100, 16);
181this.label3.TabIndex = 0;
182this.label3.Text = "本机IP地址:";
183//
184// textBox1
185//
186this.textBox1.Location = new System.Drawing.Point(104, 40);
187this.textBox1.Name = "textBox1";
188this.textBox1.Size = new System.Drawing.Size(160, 21);
189this.textBox1.TabIndex = 1;
190this.textBox1.Text = "";
191//
192// label1
193//
194this.label1.Location = new System.Drawing.Point(16, 48);
195this.label1.Name = "label1";
196this.label1.Size = new System.Drawing.Size(100, 16);
197this.label1.TabIndex = 0;
198this.label1.Text = "服务端IP地址:";
199//
200// label2
201//
202this.label2.Location = new System.Drawing.Point(64, 24);
203this.label2.Name = "label2";
204this.label2.Size = new System.Drawing.Size(100, 16);
205this.label2.TabIndex = 0;
206this.label2.Text = "文件名:";
207//
208// textBox2
209//
210this.textBox2.Location = new System.Drawing.Point(120, 16);
211this.textBox2.Name = "textBox2";
212this.textBox2.ReadOnly = true;
213this.textBox2.Size = new System.Drawing.Size(160, 21);
214this.textBox2.TabIndex = 1;
215this.textBox2.Text = "";
216//
217// textBox8
218//
219this.textBox8.Location = new System.Drawing.Point(120, 64);
220this.textBox8.Name = "textBox8";
221this.textBox8.ReadOnly = true;
222this.textBox8.Size = new System.Drawing.Size(160, 21);
223this.textBox8.TabIndex = 5;
224this.textBox8.Text = "";
225//
226// textBox9
227//
228this.textBox9.Location = new System.Drawing.Point(120, 88);
229this.textBox9.Name = "textBox9";
230this.textBox9.ReadOnly = true;
231this.textBox9.Size = new System.Drawing.Size(80, 21);
232this.textBox9.TabIndex = 4;
233this.textBox9.Text = "";
234//
235// label8
236//
237this.label8.Location = new System.Drawing.Point(40, 72);
238this.label8.Name = "label8";
239this.label8.Size = new System.Drawing.Size(80, 16);
240this.label8.TabIndex = 8;
241this.label8.Text = "包的总数量:";
242//
243// label10
244//
245this.label10.Location = new System.Drawing.Point(8, 96);
246this.label10.Name = "label10";
247this.label10.Size = new System.Drawing.Size(120, 16);
248this.label10.TabIndex = 9;
249this.label10.Text = "最后一个包的大小:";
250//
251// label11
252//
253this.label11.Location = new System.Drawing.Point(200, 96);
254this.label11.Name = "label11";
255this.label11.Size = new System.Drawing.Size(96, 16);
256this.label11.TabIndex = 7;
257this.label11.Text = "(单位:字节)";
258//
259// label12
260//
261this.label12.Location = new System.Drawing.Point(16, 120);
262this.label12.Name = "label12";
263this.label12.Size = new System.Drawing.Size(104, 16);
264this.label12.TabIndex = 6;
265this.label12.Text = "已接收包的数量:";
266//
267// textBox10
268//
269this.textBox10.Location = new System.Drawing.Point(120, 112);
270this.textBox10.Name = "textBox10";
271this.textBox10.ReadOnly = true;
272this.textBox10.Size = new System.Drawing.Size(80, 21);
273this.textBox10.TabIndex = 3;
274this.textBox10.Text = "";
275//
276// progressBar1
277//
278this.progressBar1.Location = new System.Drawing.Point(8, 152);
279this.progressBar1.Name = "progressBar1";
280this.progressBar1.Size = new System.Drawing.Size(392, 23);
281this.progressBar1.Step = 1;
282this.progressBar1.TabIndex = 10;
283//
284// textBox3
285//
286this.textBox3.Location = new System.Drawing.Point(120, 40);
287this.textBox3.Name = "textBox3";
288this.textBox3.ReadOnly = true;
289this.textBox3.Size = new System.Drawing.Size(160, 21);
290this.textBox3.TabIndex = 5;
291this.textBox3.Text = "";
292//
293// label5
294//
295this.label5.Location = new System.Drawing.Point(48, 48);
296this.label5.Name = "label5";
297this.label5.Size = new System.Drawing.Size(72, 16);
298this.label5.TabIndex = 8;
299this.label5.Text = "包的大小:";
300//
301// label6
302//
303this.label6.Location = new System.Drawing.Point(288, 48);
304this.label6.Name = "label6";
305this.label6.Size = new System.Drawing.Size(96, 16);
306this.label6.TabIndex = 7;
307this.label6.Text = "(单位:字节)";
308//
309// EzoneReceive
310//
311this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
312this.ClientSize = new System.Drawing.Size(410, 311);
313this.Controls.Add(this.groupBox3);
314this.Controls.Add(this.groupBox2);
315this.Controls.Add(this.groupBox1);
316this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
317this.MaximizeBox = false;
318this.Name = "EzoneReceive";
319this.Text = "亿众国际点对点文件传输软体接收端";
320this.Load += new System.EventHandler(this.EzoneReceive_Load);
321this.groupBox1.ResumeLayout(false);
322this.groupBox3.ResumeLayout(false);
323this.groupBox2.ResumeLayout(false);
324this.ResumeLayout(false);
325
326}
327#endregion
328
329/// <summary>
330/// 应用程序的主入口点。
331/// </summary>
332[STAThread]
333static void Main()
334{
335Application.Run(new EzoneReceive());
336}
337
338private void button1_Click(object sender, System.EventArgs e)
339{
340//开启接收线程
341Thread TempThread=new Thread(new ThreadStart(this.StartReceive));
342TempThread.Start();
343this.button1.Enabled=false;
344}
345
346private void EzoneReceive_Load(object sender, System.EventArgs e)
347{
348//获得本机的IP地址
349this.textBox4.Text=Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
350}
351
352private void StartReceive()
353{
354//指向远程服务端节点
355IPEndPoint ipep=new IPEndPoint(IPAddress.Parse(this.textBox1.Text),int.Parse(this.textBox5.Text));
356//创建套接字
357Socket client=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
358//连接到发送端
359client.Connect(ipep);
360//获得[文件名]
361string SendFileName=System.Text.Encoding.Unicode.GetString(CommonModule.EzoneModule.ReceiveVarData(client));
362this.textBox2.Text=SendFileName;
363//获得[包的大小]
364this.textBox3.Text=System.Text.Encoding.Unicode.GetString(CommonModule.EzoneModule.ReceiveVarData(client));
365//获得[包的总数量]
366this.textBox8.Text=System.Text.Encoding.Unicode.GetString(CommonModule.EzoneModule.ReceiveVarData(client));
367this.progressBar1.Maximum=int.Parse(this.textBox8.Text);
368//获得[最后一个包的大小]
369this.textBox9.Text=System.Text.Encoding.Unicode.GetString(CommonModule.EzoneModule.ReceiveVarData(client));
370//创建一个新文件
371FileStream MyFileStream=new FileStream(SendFileName,FileMode.Create,FileAccess.Write);
372//已发送包的个数
373int SendedCount=0;
374while(true)
375{
376byte[] data=CommonModule.EzoneModule.ReceiveVarData(client);
377if(data.Length==0)
378{
379break;
380}
381else
382{
383SendedCount++;
384//将接收到的数据包写入到文件流对象
385MyFileStream.Write(data,0,data.Length);
386//显示已发送包的个数
387this.textBox10.Text=SendedCount.ToString();
388//进度条值的显示
389this.progressBar1.PerformStep();
390}
391}
392this.progressBar1.Value=this.progressBar1.Maximum;
393//关闭文件流
394MyFileStream.Close();
395//关闭套接字
396client.Close();
397this.button1.Enabled=true;
398MessageBox.Show("文件接收完毕!");
399}
400}
401}
402//////////////////////////End-亿众国际接收端////////////////////////////////////
403
404////////////////////////////Begin-公共模块//////////////////////////////////////
405using System;
406using System.Net;
407using System.Net.Sockets;
408using System.Windows.Forms;
409
410namespace CommonModule
411{
412/// <summary>
413/// Class1 的摘要说明。
414/// </summary>
415public class EzoneModule
416{
417public EzoneModule()
418{
419//
420// TODO: 在此处添加构造函数逻辑
421//
422}
423
424public static int SendData(Socket s,byte[] data)
425{
426int total=0;
427int size=data.Length;
428int dataleft=size;
429int sent;
430
431while(total<size)
432{
433sent=s.Send(data,total,dataleft,SocketFlags.None);
434total+=sent;
435dataleft-=sent;
436}
437
438return total;
439}
440
441public static byte[] ReceiveData(Socket s,int size)
442{
443int total=0;
444int dataleft=size;
445byte[] data=new byte[size];
446int recv;
447while(total<size)
448{
449recv=s.Receive(data,total,dataleft,SocketFlags.None);
450if(recv==0)
451{
452data=null;
453break;
454}
455
456total+=recv;
457dataleft-=recv;
458}
459return data;
460}
461
462public static int SendVarData(Socket s,byte[] data)
463{
464int total=0;
465int size=data.Length;
466int dataleft=size;
467int sent;
468byte[] datasize=new byte[4];
469datasize=BitConverter.GetBytes(size);
470sent=s.Send(datasize);
471
472while(total<size)
473{
474sent=s.Send(data,total,dataleft,SocketFlags.None);
475total+=sent;
476dataleft-=sent;
477}
478
479return total;
480}
481
482public static byte[] ReceiveVarData(Socket s)
483{
484int total=0;
485int recv;
486byte[] datasize=new byte[4];
487recv=s.Receive(datasize,0,4,SocketFlags.None);
488int size=BitConverter.ToInt32(datasize,0);
489int dataleft=size;
490byte[] data=new byte[size];
491while(total<size)
492{
493recv=s.Receive(data,total,dataleft,SocketFlags.None);
494if(recv==0)
495{
496data=null;
497break;
498}
499total+=recv;
500dataleft-=recv;
501}
502return data;
503}
504}
505}
506
507/////////////////////////////End-公共模块///////////////////////////////////////</packetcount;i++)>