日期:2014-05-17 浏览次数:20775 次
private void StartListen()
{
listener = new TcpListener(ipep);
listener.Start();
while (true)
{
Socket clientSocket = listener.AcceptSocket();
Thread clientThread = new Thread(new ParameterizedThreadStart(SocketWork));
CheckForIllegalCrossThreadCalls = false;//不捕获对错误线程的调用
clientThread.IsBackground = true;
clientThread.Start(clientSocket);
}
}
private void SocketWork(object objSocket)
{
Socket socket = (Socket)objSocket;
//
//省略中间收发的代码
//
Client cl = new Client(clientName, socket.RemoteEndPoint, socket, Thread.CurrentThread);
clientList.Add(cl);
}
private void Gone(string str, Socket socket)
{
string[] token = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
string name = token[1];
Client cl=null;
foreach (object obj in clientList)
{
Client c = (Client)obj;
if (c.Name != name)
{
SendMsgToClient.Send(c, str);//发