CommonModule 求详解

liyongfei521 2011-12-06 12:58:37
CommonModule在这里面是什么? 求详解~

客户端代码:
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 发送端
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
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 = "文件信息";
//
// 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;
//
// 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;
//
// 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 = "文件大小:";
//
// 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 = "文件名:";
//
// 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);
//
// 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;
//
// 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 = "(单位:字节)";
//
// openFileDialog1
//
this.openFileDialog1.Filter = "所有文件|*.*";
//
// 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 = "系统设置";
//
// 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";
//
// 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 = "2005";
//
// 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 = "传输端口:";
//
// 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;
//
// 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地址:";
//
// 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 = "包的大小:";

}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
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.Parse("192.168.1.136"), int.Parse(this.textBox5.Text));
////MessageBox.Show(IPAddress.Any);
////创建一个套接字
//Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//MessageBox.Show(server.ToString());

//指向远程服务端节点
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.168.1.136"), int.Parse(this.textBox5.Text));
//创建套接字
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//连接到发送端
client.Connect(ipep);


////绑定套接字到端口
//client.Bind(ipep);
//MessageBox.Show(ipep.ToString());
////开始侦听(并堵塞该线程)
//server.Listen(10);
//确认连接
//Socket client = server.Accept();
//MessageBox.Show(client.ToString());



//获得客户端节点对象
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<PacketCount;i++)
{
//从文件流读取数据并填充数据包
EzoneStream.Read(data,0,data.Length);
//发送数据包
CommonModule.EzoneModule.SendVarData(client,data);
//显示发送数据包的个数
this.textBox10.Text=((int)(i+1)).ToString();
//进度条值的显示
this.progressBar1.PerformStep();
}
//如果还有多余的数据包,则应该发送完毕!
if(LastDataPacket!=0)
{
data=new byte[LastDataPacket];
EzoneStream.Read(data,0,data.Length);
CommonModule.EzoneModule.SendVarData(client,data);
this.progressBar1.Value=this.progressBar1.Maximum;
}
//关闭套接字
client.Close();
//server.Close();
//关闭文件流
EzoneStream.Close();
this.button2.Enabled=true;
MessageBox.Show("文件传输完毕!");
}

private void button2_Click(object sender, System.EventArgs e)
{
//开启文件传输子线程
Thread TempThread=new Thread(new ThreadStart(this.StartSend));
TempThread.Start();
this.button2.Enabled=false;
}
private void EzoneSend_Load(object sender, System.EventArgs e)
{
//获得本机的IP地址
this.textBox4.Text=Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
}
}
}
...全文
182 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccccffff 2012-01-14
  • 打赏
  • 举报
回复
CommonModule你都没定义过?怎么用属性??
public Module CommonModule
属性的定义。
end Module

然后在调用的地方才能点的出
feng1989612 2012-01-14
  • 打赏
  • 举报
回复
为什么点不出CommonModule的属性呢???
liyongfei521 2011-12-07
  • 打赏
  • 举报
回复
能在详细一点么 或者你有关于这个类的资料 发给我 1491461375@qq.com 跪谢~~!
阿非 2011-12-06
  • 打赏
  • 举报
回复
自定义的封装类

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧