有两个错误,
一:
CSocket cs; 
if(server.Accept(cs)) 

AfxBeginThread(csComm,&cs); 



}


}
//此时cs销毁,AfxBeginThread(csComm,&cs)传出的地址已无效,在csComm肯定会引发访问违例。
二:CSocket对象不能在不同的线程中使用。应写为
UINT waitaccept(LPVOID lpParam) 

CSocket cs; 
if(server.Accept(cs)) 

SOCKET hSocket;
hSocket=cs.Detach();
AfxBeginThread(csComm,hSocket); 
usercount++; 
AfxBeginThread(waitaccept,NULL); 

else 
AfxBeginThread(waitaccept,NULL); 
} UINT csComm(LPVOID lpParam) 

CSocket cs; 
cs.Attach(hSocket);
//通信代码 
cs->Send(...); 
cs->Recv(...);..... 
//释放资源....