日期:2014-05-17 浏览次数:21044 次
void asyncAcceptCall(IAsyncResult ar)
{
//服务器的Socket
//AsyncState 状态 获取用户定义的对象
Socket ServerSocket = (Socket)ar.AsyncState;
//异步接受传入的连接尝试,并创建新的 Socket 来处理远程主机通信
Socket ClientSocket = ServerSocket.EndAccept(ar);
IPEndPoint ipEnde = (IPEndPoint)ClientSocket.RemoteEndPoint;
SocketInfo socketInfo = new SocketInfo();
allDone.Set();
try
{
readDone.Reset();
if (ClientSocket.Connected)
{
socketInfo.Client.BeginReceive(
socketInfo.Buff,
0,
2048,
SocketFlags.None,
new AsyncCallback(asynReceCall),
socketInfo