45fan.com - 路饭网
首页
路由器设置
无线路由器
路由器密码
网络频道
手机频道
电脑频道
图库频道
问答中心
搜索:
智能搜索
搜索标题
您的位置
:
主页
>
电脑频道
>
电脑教程
> 阅读资讯:异步通信实例的详细介绍
异步通信实例的详细介绍
2016-08-31 16:47:25 来源:www.45fan.com 【
大
中
小
】
异步通信实例的详细介绍
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
using
System.Text;
using
System.Net;
using
System.Net.Sockets;
using
System.Threading;
namespace
TServer
...
{
/**/
///
<summary>
///
Form1的摘要说明。
///
</summary>
public
class
Form1:System.Windows.Forms.Form
...
{
private
System.Windows.Forms.TextBoxtxt;
private
System.Net.Sockets.Socketserver;
private
System.Windows.Forms.ComboBoxcmbIP;
private
System.Windows.Forms.ButtonbtnStart;
private
System.Windows.Forms.ButtonbtnStop;
private
System.Windows.Forms.StatusBarstatBar;
private
System.Threading.ManualResetEventallDone;
private
byte
[]buffer;
/**/
///
<summary>
///
必需的设计器变量。
///
</summary>
private
System.ComponentModel.Containercomponents
=
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);
}
Windows窗体设计器生成的代码
#region
Windows窗体设计器生成的代码
/**/
///
<summary>
///
设计器支持所需的方法-不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
...
{
this
.txt
=
new
System.Windows.Forms.TextBox();
this
.cmbIP
=
new
System.Windows.Forms.ComboBox();
this
.btnStart
=
new
System.Windows.Forms.Button();
this
.btnStop
=
new
System.Windows.Forms.Button();
this
.statBar
=
new
System.Windows.Forms.StatusBar();
this
.SuspendLayout();
//
//
txt
//
this
.txt.Anchor
=
((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom
|
System.Windows.Forms.AnchorStyles.Left)
|
System.Windows.Forms.AnchorStyles.Right)));
this
.txt.Location
=
new
System.Drawing.Point(
0
,
40
);
this
.txt.Multiline
=
true
;
this
.txt.Name
=
"
txt
"
;
this
.txt.Size
=
new
System.Drawing.Size(
472
,
232
);
this
.txt.TabIndex
=
0
;
this
.txt.Text
=
""
;
//
//
cmbIP
//
this
.cmbIP.DropDownStyle
=
System.Windows.Forms.ComboBoxStyle.DropDownList;
this
.cmbIP.Location
=
new
System.Drawing.Point(
8
,
8
);
this
.cmbIP.Name
=
"
cmbIP
"
;
this
.cmbIP.Size
=
new
System.Drawing.Size(
144
,
20
);
this
.cmbIP.TabIndex
=
1
;
//
//
btnStart
//
this
.btnStart.FlatStyle
=
System.Windows.Forms.FlatStyle.Popup;
this
.btnStart.Location
=
new
System.Drawing.Point(
168
,
8
);
this
.btnStart.Name
=
"
btnStart
"
;
this
.btnStart.TabIndex
=
2
;
this
.btnStart.Text
=
"
开始
"
;
this
.btnStart.Click
+=
new
System.EventHandler(
this
.btnStart_Click);
//
//
btnStop
//
this
.btnStop.FlatStyle
=
System.Windows.Forms.FlatStyle.Popup;
this
.btnStop.Location
=
new
System.Drawing.Point(
272
,
8
);
this
.btnStop.Name
=
"
btnStop
"
;
this
.btnStop.TabIndex
=
2
;
this
.btnStop.Text
=
"
停止
"
;
//
//
statBar
//
this
.statBar.Location
=
new
System.Drawing.Point(
0
,
272
);
this
.statBar.Name
=
"
statBar
"
;
this
.statBar.Size
=
new
System.Drawing.Size(
472
,
22
);
this
.statBar.TabIndex
=
3
;
//
//
Form1
//
this
.AutoScaleBaseSize
=
new
System.Drawing.Size(
6
,
14
);
this
.ClientSize
=
new
System.Drawing.Size(
472
,
294
);
this
.Controls.Add(
this
.statBar);
this
.Controls.Add(
this
.btnStart);
this
.Controls.Add(
this
.cmbIP);
this
.Controls.Add(
this
.txt);
this
.Controls.Add(
this
.btnStop);
this
.Name
=
"
Form1
"
;
this
.Text
=
"
服务器端
"
;
this
.Load
+=
new
System.EventHandler(
this
.Form1_Load);
this
.ResumeLayout(
false
);
}
#endregion
/**/
///
<summary>
///
应用程序的主入口点。
///
</summary>
[STAThread]
static
void
Main()
...
{
Application.Run(
new
Form1());
}
private
void
Form1_Load(
object
sender,System.EventArgse)
...
{
this
.server
=
new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
this
.allDone
=
new
ManualResetEvent(
true
);
this
.cmbIP.Items.Clear();
foreach
(IPAddressip
in
Dns.GetHostByName(Dns.GetHostName()).AddressList)
...
{
this
.cmbIP.Items.Add(ip.ToString());
}
if
(
this
.cmbIP.Items.Count
>
0
)
this
.cmbIP.SelectedIndex
=
0
;
this
.statBar.Text
=
"
初始
本文地址:
http://www.45fan.com/dnjc/70326.html
Tags:
实例
异步
通信
编辑:路饭网
上一篇:
Data Guard配置手记的知识内容介绍
下一篇:
.Net 2005 TreeView控件的一个问题有哪些?
相关文章列表
Zend Framework教程之请求对象的封装Zend
使用UG画键槽的方法
如何在工业过程中控制领域中通信?
恢复硬盘数据的诀窍
如何利用Flash作为桥梁连接WEB页面和服务
Winsock网络通信的详细信息
ASP服务器端组件编程实例介绍
Hibernate操作视图实例介绍
如何用邮槽实现进程间的通信?
实现异步的技巧
推广内容
推荐阅读
热门推荐
推荐文章
·
如何为Excel2010表格中的图表添加说明文
·
Win7系统看电影时,如果有QQ消息,电影声
·
WPS文字文档中,如何给指定的文字添加边
·
盘点制作PPT时常用的一些快捷键大全
·
分享一组Win8系统不太为人所知的小技巧
·
系统遇到特殊故障时,如何进入Win10系统
·
电脑系统损坏要如何修复?修复win10系统
·
想找回关闭的网页该怎么办?怎样查看360
·
实现电脑每天定时关机,借助Win7任务计划
·
什么是Telnet协议?Win7如何开启Telnet服
·
电脑时间出现差错时如何进行北京时间校准
·
电脑运行速度慢,C盘空间越来越小,如何
关于我们
|
联系我们
|
友情链接
|
网站地图
|
Sitemap
|
App
|
返回顶部