日期:2008-05-17  浏览次数:20432 次

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;

using System.Windows.Forms;
using System.Data;
using Jh.Sockets;
using System.IO;

namespace Jh.Test
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class JhSocketTest : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnServerStart;
private System.Windows.Forms.Button btnServerStop;
private System.Windows.Forms.Button btnClientConnect;
private System.Windows.Forms.Button btnClientStop;
private System.Windows.Forms.Button btnServerSend;
private System.Windows.Forms.Button btnClientSend;
private System.Windows.Forms.Button btnStopClient;
private System.Windows.Forms.RichTextBox lbClient;
private System.Windows.Forms.RichTextBox lbServer;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public JhSocketTest()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
server = new JhTcpServer(6008);
serverOb = new MyOb(this);
server.AddOb(serverOb);
clientOb = new MyClientOb(this);
client = new JhClient(clientOb);
client.OnConnectFailed += new CommEventHandler(ConnectEvent);
client.OnConnected += new CommEventHandler(ConnectEvent);
client.OnClosed += new CommEventHandler(ConnectEvent);
client.ConnectCheck = true;
}
MyClientOb clientOb;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
server.Exit();
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnServerStart = new System.Windows.Forms.Button();
this.btnServerStop = new System.Windows.Forms.Button();
this.btnClientConnect = new System.Windows.Forms.Button();
this.btnClientStop = new System.Windows.Forms.Button();
this.btnServerSend = new System.Windows.Forms.Button();
this.btnClientSend = new System.Windows.Forms.Button();
this.btnStopClient = new System.Windows.Forms.Button();
this.lbClient = new System.Windows.Forms.RichTextBox();
this.lbServer = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// btnServerStart
//
this.btnServerStart.Location = new System.Drawing.Point(11, 6);
this.btnServerStart.Name = "btnServerStart";
this.btnServerStart.Size = new System.Drawing.Size(116, 23);
this.btnServerStart.TabIndex = 0;
this.btnServerStart.Text = "Server Start";
this.btnServerStart.Click += new System.EventHandler(this.btnServerStart_Click);
//
// btnServerStop
//
this.btnServerStop.Location = new System.Drawing.Point(135, 7);
this.btnServerStop.Name = "btnServerStop";
this.btnServerStop.Size = new System.Drawing.Size(134, 23);
this.btnServerStop.TabIndex = 1;
this.btnServerStop.Text = "Server Stop";
this.btnServerStop.Click += new System.EventHandler(this.btnServerStop_Click);
//
// btnClientConnect
//
this.btnClientConnect.Locati