示例#1
0
        /// <summary>
        /// Stops accepting connections and disconnects all connected clients.
        /// </summary>
        public void stopServer()
        {
            if (state == ServerState.STOPPED)
            {
                throw new InvalidServerStateException("Server has not been started");
            }
            try
            {
                serverListener.Stop();
                frameQueue.stopQueue();
                serverListener = null;
                state          = ServerState.STOPPED;

                //kill all sockets by closing them first and then
                //clearning the socket queue
                foreach (KeyValuePair <int, VideoSocketHandler> set in socketList)
                {
                    VideoSocketHandler closeme;
                    if (socketList.TryRemove(set.Key, out closeme))
                    {
                        closeme.close();
                    }
                }
                socketList.Clear();
            }
            catch (SocketException)
            {
                Log.warn("SocketException occured in stopServer(). Can we safely ignore this?");
            }
        }