日期:2011-05-10 浏览次数:20363 次
/********************************8ChatServer:*************************************************/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Net.Sockets;
using System.Net;
namespace Chat_Server
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
static int listenport=6666;
Socket clientsocket;
private System.Windows.Forms.ListBox lbClients;
ArrayList clients;
private System.Windows.Forms.Button button1;
Thread clientservice;
private System.Windows.Forms.Label label1;
Thread threadListen;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(clientservice != null)
{
clientservice.Abort();
}
if(threadListen != null)
{
try
{
threadListen.Abort();
}
catch(Exception ex)
{
threadListen = null;
}
}
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lbClients = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lbClients
//
this.lbClients.ItemHeight = 12;
this.lbClients.Location = new System.Drawing.Point(16, 24);
this.lbClients.Name = "lbClients";
this.lbClients.Size = new System.Drawing.Size(184, 268);
this.lbClients.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(272, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(240, 136);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 32);
this.label1.TabIndex = 2;
this.label1.