以下是客户端using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Data;
using System.IO.IsolatedStorage;namespace tencent
{
/// <summary>
/// login 的摘要说明。
/// </summary>
///  public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
//chart_socket my_socket =new chart_socket();

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private static string ip_address;
private Socket m_socket=null;
private System.Windows.Forms.TextBox ID;
private System.Windows.Forms.TextBox PWD;
private byte[] m_byBuff=new byte[256];
private byte[] m_byteBuff=new byte[256];
delegate void AddMessage(string sNewMessage);
private event AddMessage m_AddMessage;
flash_login flash =new flash_login();

public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
m_AddMessage=new AddMessage(OnAddMessage);
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.ID = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.PWD = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
// 
// label1
// 
this.label1.Location = new System.Drawing.Point(16, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 0;
this.label1.Text = "登录ID";
// 
// ID
// 
this.ID.Location = new System.Drawing.Point(72, 16);
this.ID.Name = "ID";
this.ID.Size = new System.Drawing.Size(152, 21);
this.ID.TabIndex = 1;
this.ID.Text = "";
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(40, 96);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// label2
// 
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 3;
this.label2.Text = "密码";
// 
// PWD
// 
this.PWD.Location = new System.Drawing.Point(72, 51);
this.PWD.Name = "PWD";
this.PWD.Size = new System.Drawing.Size(152, 21);
this.PWD.TabIndex = 4;
this.PWD.Text = "";
// 
// button2
// 
this.button2.Location = new System.Drawing.Point(152, 96);
this.button2.Name = "button2";
this.button2.TabIndex = 5;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
// 
// login
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(272, 133);
this.Controls.Add(this.button2);
this.Controls.Add(this.PWD);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.ID);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.Name = "login";
this.Text = "登录窗口";
this.ResumeLayout(false); }
#endregion private string  GetIpAddress()  //得到远程主机的IP地址
{
ip_address="10.0.0.47";
return ip_address;
}
private void button1_Click(object sender, System.EventArgs e)  //发送数据
{
try
{
if(m_socket!=null && m_socket.Connected)
{
m_socket.Shutdown(SocketShutdown.Both);
System.Threading.Thread.Sleep(10);
m_socket.Close();
}
string ls_IPAddress =GetIpAddress();
m_socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint epServer =new IPEndPoint(IPAddress.Parse(ls_IPAddress),399);
m_socket.Blocking=false;
AsyncCallback onconnect=new AsyncCallback(OnConnect);
m_socket.BeginConnect(epServer,onconnect,m_socket);
this.Visible=false;
flash.Show();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"不能连接到服务器!");
}
} public void OnConnect(IAsyncResult ar)
{
Socket sock =(Socket)ar.AsyncState;
try
{
if(sock.Connected)
SetupRecieveCallback(sock);
else
MessageBox.Show("不能连接主机!");
} catch(Exception ex)
{
MessageBox.Show(ex.Message,"错误!");
}
} public void SetupRecieveCallback(Socket sock)
{
try
{
//开始接收数据
   AsyncCallback receieveData =new AsyncCallback(OnRecievedData);
   sock.BeginReceive(m_byteBuff,0,m_byteBuff.Length,SocketFlags.Peek,receieveData,sock);
//开始发送数据
   byte[] byteDataID =System.Text.ASCIIEncoding.ASCII.GetBytes(ID.Text.ToCharArray());
   byte[] byteDataPWD=System.Text.ASCIIEncoding.ASCII.GetBytes(PWD.Text.ToCharArray());
   string ls_senddata =ID.Text + "+"+ PWD.Text;
   //MessageBox.Show(ls_senddata);
   byte[] byteIDPWD =System.Text.ASCIIEncoding.ASCII.GetBytes(ls_senddata.ToCharArray());
   sock.Send(byteIDPWD,0,byteIDPWD.Length,SocketFlags.None);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"错误!");
}
} public void OnRecievedData( IAsyncResult ar) 

{ Socket sock = (Socket)ar.AsyncState;
try 
{
int nBytesRec = sock.EndReceive( ar );  //结束挂起的异步读取
if( nBytesRec > 0 ) 
{
string sRecieved = System.Text.Encoding.ASCII.GetString( m_byBuff, 0, nBytesRec );
                    Invoke( m_AddMessage, new string [] { sRecieved } );
SetupRecieveCallback( sock );   //时间回调
}
else 
{
//Console.WriteLine( "Client {0}, disconnected", sock.RemoteEndPoint );
sock.Shutdown( SocketShutdown.Both ); //禁止用socket发送接受数据
sock.Close();
}
}
catch( Exception ex ) 
{
MessageBox.Show( this, ex.Message, "接受数据失败!" );
}
}
private void OnAddMessage(string sMessage)
{

//MessageBox.Show(sMessage);
//接收到的消息
if(sMessage=="ok")
{
flash.Close();
}
}
private void button2_Click(object sender, System.EventArgs e)   //退出
{
this.Close();
} }
}在处理连接的时候怎么象QQ那样??
或者给个QQ的系统思想!详细点的》》