异步通信实例的详细介绍
异步通信实例的详细介绍
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
usingSystem.Text;
usingSystem.Net;
usingSystem.Net.Sockets;
usingSystem.Threading;
namespaceTServer
{
///<summary>
///Form1的摘要说明。
///</summary>
publicclassForm1:System.Windows.Forms.Form
{
privateSystem.Windows.Forms.TextBoxtxt;
privateSystem.Net.Sockets.Socketserver;
privateSystem.Windows.Forms.ComboBoxcmbIP;
privateSystem.Windows.Forms.ButtonbtnStart;
privateSystem.Windows.Forms.ButtonbtnStop;
privateSystem.Windows.Forms.StatusBarstatBar;
privateSystem.Threading.ManualResetEventallDone;
privatebyte[]buffer;
///<summary>
///必需的设计器变量。
///</summary>
privateSystem.ComponentModel.Containercomponents=null;
publicForm1()
{
//
//Windows窗体设计器支持所必需的
//
InitializeComponent();
//
//TODO:在InitializeComponent调用后添加任何构造函数代码
//
}
///<summary>
///清理所有正在使用的资源。
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
Windows窗体设计器生成的代码
///<summary>
///应用程序的主入口点。
///</summary>
[STAThread]
staticvoidMain()
{
Application.Run(newForm1());
}
privatevoidForm1_Load(objectsender,System.EventArgse)
{
this.server=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
this.allDone=newManualResetEvent(true);
this.cmbIP.Items.Clear();
foreach(IPAddressipinDns.GetHostByName(Dns.GetHostName()).AddressList)
{
this.cmbIP.Items.Add(ip.ToString());
}
if(this.cmbIP.Items.Count>0)
this.cmbIP.SelectedIndex=0;
this.statBar.Text="初始
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
usingSystem.Text;
usingSystem.Net;
usingSystem.Net.Sockets;
usingSystem.Threading;
namespaceTServer
{
///<summary>
///Form1的摘要说明。
///</summary>
publicclassForm1:System.Windows.Forms.Form
{
privateSystem.Windows.Forms.TextBoxtxt;
privateSystem.Net.Sockets.Socketserver;
privateSystem.Windows.Forms.ComboBoxcmbIP;
privateSystem.Windows.Forms.ButtonbtnStart;
privateSystem.Windows.Forms.ButtonbtnStop;
privateSystem.Windows.Forms.StatusBarstatBar;
privateSystem.Threading.ManualResetEventallDone;
privatebyte[]buffer;
///<summary>
///必需的设计器变量。
///</summary>
privateSystem.ComponentModel.Containercomponents=null;
publicForm1()
{
//
//Windows窗体设计器支持所必需的
//
InitializeComponent();
//
//TODO:在InitializeComponent调用后添加任何构造函数代码
//
}
///<summary>
///清理所有正在使用的资源。
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
Windows窗体设计器生成的代码
///<summary>
///应用程序的主入口点。
///</summary>
[STAThread]
staticvoidMain()
{
Application.Run(newForm1());
}
privatevoidForm1_Load(objectsender,System.EventArgse)
{
this.server=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
this.allDone=newManualResetEvent(true);
this.cmbIP.Items.Clear();
foreach(IPAddressipinDns.GetHostByName(Dns.GetHostName()).AddressList)
{
this.cmbIP.Items.Add(ip.ToString());
}
if(this.cmbIP.Items.Count>0)
this.cmbIP.SelectedIndex=0;
this.statBar.Text="初始