/// <summary> /// 停止服务器 /// </summary> public void Stop() { Serverconfig.m_daemonThread.Close(); IsStartListening = false; listenSocket.Close(); m_asyncSocketUserList.Userlist = null; m_asyncSocketDeviceList = null; GC.Collect(); }
/// <summary> /// 用户池初始化 /// </summary> public void Init() { Serverconfig = new ServerConfig(); m_asyncSocketUserList = new SocketUserClientList(); m_asyncSocketDeviceList = new SocketDeviceClientList(); m_asyncSocketUserTokenPool = new AsyncSocketUserPool(serverconfig.numConnections); SocketUserToken userToken; for (int i = 0; i < serverconfig.numConnections; i++) //按照连接数建立读写对象 { userToken = new SocketUserToken(serverconfig.buffSize); //异步回调函数初始化 userToken.ReceiveEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed); //异步回调函数初始化 userToken.SendEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed); //开辟固定空间 m_asyncSocketUserTokenPool.Push(userToken); } }