Exemple #1
0
        /// <summary>
        /// Raises when a client received a completed <see cref="Package"/>.
        /// Not calling the base implementation of this methods will cause the client
        /// to malfunction.
        /// </summary>
        /// <param name="package">The package that has been received.</param>
        protected override void OnPackageReceived(Package package)
        {
            base.OnPackageReceived(package);

            switch ((BaseCommand)package.Command)
            {
            case BaseCommand.ConnectionRefused:

                ResetClient();
                var args = ConnectionRefusedContent.Deserialize(package.Content);
                OnConnectionRefused(args);
                break;

            case BaseCommand.ServerClosed:
                var content = ServerClosedContent.Deserialize(package.Content);
                ResetClient();
                OnServerClosed(content);
                break;
            }
        }
        /// <summary>
        /// Stops the server.
        /// </summary>
        /// <exception cref="SocketException"></exception>
        /// <exception cref="ObjectDisposedException"></exception>
        public void Stop(string serverClosedMessage = "")
        {
            if (enabled)
            {
                timerSolicitorChecker.Stop();
                timerTimedOutChecker.Stop();
                var     content = new ServerClosedContent(serverClosedMessage);
                Package package = new Package(BaseCommand.ServerClosed, content.Serialize());

                foreach (ServerSideClient client in clients)
                {
                    client.SendPackageAsync(package);
                    client.Socket.Shutdown(SocketShutdown.Both);
                    client.Socket.Close();
                }

                clients.Clear();
                clientNames.Clear();
                Enabled = false;
                serverSocket.Close();
            }
        }
Exemple #3
0
 /// <summary>
 /// Raises when the server has closed.
 /// </summary>
 /// <param name="content">Content describing the occurrence.</param>
 protected virtual void OnServerClosed(ServerClosedContent content)
 {
     Pusher.Push(content);
 }