日期:2014-05-19  浏览次数:21046 次

Client这个类是哪个命名空间的?
using   System;
using   System.Drawing;
using   System.Collections;
using   System.ComponentModel;
using   System.Windows.Forms;
using   System.Data;
using   System.Net;
using   System.Threading;
using   System.Net.Sockets;
namespace   聊天程序
{
///   <summary>
///   Form1   的摘要说明。
///   </summary>
public   class   frmServer   :   System.Windows.Forms.Form
{
private   System.Windows.Forms.Label   lblServer;
private   System.Windows.Forms.ListBox   lstClients;
private   System.Windows.Forms.Button   btnExit;
///   <summary>
///   必需的设计器变量。
///   </summary>
///  

private   ArrayList   clients;
private   int   listenport=5555;
private   TcpListener   listener;
private   Thread   processor;
private   Socket   clientsocket;
private   Thread   clientservice;
private   System.ComponentModel.Container   components   =   null;

public   frmServer()
{
InitializeComponent();
clients=new   ArrayList();
processor=new   Thread(new   ThreadStart(StartListening));
processor.Start();
}

///   <summary>
///   清理所有正在使用的资源。
///   </summary>
protected   override   void   Dispose(   bool   disposing   )
{
if(   disposing   )
{
if   (components   !=   null)  
{
components.Dispose();
}
}
base.Dispose(   disposing   );
}

protected   override   void   OnClosed(EventArgs   e)
{
try
{
for(int   n=0;n <clients.Count;n++)
{
Client   cl=(Client)clients[n];
SendToClient(cl, "QUIT| ");



}
}
catch{};
}
private   void   StartListening()
{
listener=new   TcpListener(listenport);
listener.Start();
while(true)
{
try
{
Socket   a=listener.AcceptSocket();
clientsocket=s;
clientservice=new   Thread(new   ThreadStart(serviceClient));
clientservice.Start();
}
catch(Exception   e)
{
Console.WriteLine(e.ToString());
}
}
}
private   void   serviceClient()
{
Socket   client   =clientsocket;
bool   keepalive=true;
while(keepalive)
{
Byte[]   buffer=new   Byte[1024];
client.Receive(buffer);
string   clientcommand=System.Text.Encoding.ASCII.GetString(buffer);
string[]   tokens=clientcommand.Split(new   char[]{ '| '});
Console.WriteLine(clientcommand);
if(tokens[0])
{
for(int   n=0;n <clients.Count;n++)
{
Client   cl=(Client)clients[n];
SendToClient(cl, "JOIN| "+tokens[1]);
}
EndPointep=client.RemoteEndPoint;
Client   c=new   Client(tokens[1],ep,clientservice,client);
clients.Add(c);

}
}
}
private   void   SendToClient(Client     cl,string   message)
{

}
private   string   GetChatterList()