public void CloseClientSocket(SocketAsyncEventArgs e) { AsyncUserToken token = e.UserToken as AsyncUserToken; try { token.ServerSocket.Shutdown(SocketShutdown.Send); } catch (Exception) { } token.Close(); Interlocked.Decrement(ref ConnectedSockets); if (null == token.IO_Completed) { token.SetComplete(IO_Completed); token.Completed(); } if (token.PlayerName != null) { Online.Remove(token.PlayerName); token.PlayerName = null; } TokenPool.Push(token); semaphore.Release(); }
public void Init() { AsyncUserToken userToken; for (int i = 0; i < MaxConnections; i++) //按照连接数建立读写对象 { userToken = new AsyncUserToken(BufferSize); userToken.SetComplete(IO_Completed); userToken.Completed(); TokenPool.Push(userToken); } }