域名频道-专业提供域名注册,网站空间,电子邮箱,VPS主机等服务
首页 域名注册 虚拟主机 香港主机 美国主机 VPS主机 网站建设 ShopEX网店 软件开发 客户中心 购物车
域名服务,域名注册 常见问题
文章搜索


本类TOP10
·松江网页设计_松江网页制...
·上海轨道交通图-上海地图
·松江公交线路图-松江地图
·marquee连续滚动
·今天几度?-天气预报-全...
·松江新城地图-松江地图
·松江城区地图-松江地图
·HAO123邮箱登陆代码
·shopex免费模板,下...
·松江DNS服务器地址,松...
当前位置:域名频道首页 > 常见问题 > 网页制作
VisualC#中托管Socket的实现方法(二) (1)

五.利用Socket来接收数据:
Vi sual C#在使用Socket来介绍网络传送来的数据时,要 解决下面三个问题,也是完成Visual C#使用Socket 来接收数据的三个步骤:
1.侦听网络,接受网络连接申请 ;
2..获得用以接收数据的Socket实例,并以此实 例接收远程主机发送来的数据;
3.根据远程主机发送来的 控制码,断开网络连接,并清除资源。
此处接收接收数据, 是上面介绍的【利用Socket来传送数据】传送来的数据。下面就是利用Socket来接收数据的具体实现步骤:
1.启动Viisual Studio .Net,并新建一个 Visual C#项目,项目名称为【利用Socket来接收数 据】。
2.把Visual Studio .Net的当 前窗口切换到【Form1.cs(设计)】窗口,并从【工具箱】 中的【Windows窗体组件】选项卡中往Form1窗体中拖入 下列组件,并执行相应操作:
一个ListBox组件,用 以显示接收的数据。
一个StausBar组件,用以显示 接收端程序的运行状况。
一个Button组件,名称为b utton1,并在这个组件被拖入窗体后,双击它,则系统会在F orm1.cs文件中自动产生其Click事件对应的处理代码。
3.【解决方案资源管理器】窗口中,双击Form1.c s文件,进入Form1.cs文件的编辑界面。
4.以下 面代码替代系统产生的InitializeComponent过 程::

 


private void InitializeCompon ent ( )
{
this.button1 = new System.Windows.Forms.But ton ( ) ;

this.listBox1 = new System.Windows.Forms.ListB ox ( ) ;

this.statusBar1 = new System.Windows.Forms.Stat usBar ( ) ;

this.SuspendLa yout ( ) ;

this.button1.Fl atStyle = System.Windows.Forms .FlatStyle.Flat ;

this.but ton1.Location = new System.Dra wing.Point ( 96 , 16 ) ;

t his.button1.Name = "
butto n1"
;

this.button1.Si ze = new System.Drawing.Size ( 80 , 34 ) ;

this.button1. TabIndex = 0 ;

this.button 1.Text = "
监听"
;

this.button1.Click += new Syst em.EventHandler ( this.button1 _Click ) ;

this.listBox1.I temHeight = 12 ;

this.list Box1.Location = new System.Dra wing.Point ( 16 , 68 ) ;

t his.listBox1.Name = "
list Box1"
;

this.listBox1 .Size = new System.Drawing.Siz e ( 258 , 172 ) ;

this.lis tBox1.TabIndex = 1 ;

this. statusBar1.Location = new Syst em.Drawing.Point ( 0 , 251 ) ;

this.statusBar1.Name = &q uot;
statusBar1"
;

thi s.statusBar1.Size = new System .Drawing.Size ( 292 , 22 ) ;
this.statusBar1.TabIndex = 2 ;

this.statusBar1.Text = "
无连接"
;

this.Au toScaleBaseSize = new System.D rawing.Size ( 6 , 14 ) ;

t his.ClientSize = new System.Dr awing.Size ( 292 , 273 ) ;

this.Controls.AddRange ( new System.Windows.Forms.Control[] {
this.statusBar1 ,
this.listBox1 ,
th is.button1} ) ;

this.FormB orderStyle = System.Windows.Fo rms.FormBorderStyle.FixedSingl e ;

this.MaximizeBox = fal se ;

this.Name = "
For m1"
;

this.Text = &qu ot;
利用Socket来接收数据"
;

t his.ResumeLayout ( false ) ;
}

来自:域名频道 时间:2006-9-19 返回 常见问题 首页
关于我们 联系方式 付款事宜 招聘启事 网站地图 域名注册 虚拟主机 法律顾问

Copyright 2000-2013 域名频道(www.DNS110.com)
地址:上海市松江区新松江路1188弄37号 邮编:201620
电话:021-67820741 67820742 67820743 传真:转分机805 值班电话:021-67820743
QQ:219854 Email:support@dns110.com