Пример #1
0
 /// <summary>
 /// Метод для остановки сервера
 /// </summary>
 public void Stop()
 {
     lock (locker)
     {
         if (ServerSocket != null)
         {
             if (ServerSocket != null)
             {
                 ServerSocket.Close();
                 ServerSocket.Dispose();
             }
             ServerSocket = null;
             foreach (var client in Сonnections.ToArray())
             {
                 try
                 {
                     CloseConnection(client);
                 }
                 catch (Exception ex)
                 {
                     CallErrorServer(ServerErrorType.CloseConnection, ex.Message);
                 }
             }
         }
         lock (Сonnections) Сonnections.Clear();
         if (IsListeningStatus)
         {
             IsListeningStatus = false;
             CallStatus(ServerStatus.Stop);
         }
     }
 }
Пример #2
0
        public void TearDown()
        {
            if (ServerSocket != null)
            {
                ServerSocket.Dispose();
                ServerSocket = null;
            }

            if (ServerListener != null)
            {
                ServerListener.Dispose();
                ServerListener = null;
            }

            if (Session != null)
            {
                Session.Dispose();
                Session = null;
            }

            if (ClientSocket != null && ClientSocket.Connected)
            {
                ClientSocket.Shutdown(SocketShutdown.Both);
                ClientSocket.Dispose();
            }
        }
Пример #3
0
 /// <summary>
 /// Метод для остановки сервера
 /// </summary>
 public void Stop()
 {
     if (ServerSocket != null)
     {
         lock (ServerSocket)
         {
             try
             {
                 ServerSocket.Shutdown(SocketShutdown.Both);
             }
             catch (Exception ex)
             {
                 CallErrorServer(ServerErrorType.CloseConnection, ex.Message);
             }
             ServerSocket.Close();
             ServerSocket.Dispose();
             ServerSocket = null;
         }
     }
     if (IsListeningStatus)
     {
         CallStatus(ServerStatus.Stop);
     }
     IsListeningStatus = false;
 }
Пример #4
0
 protected override void OnStop()
 {
     try
     {
         ISLogger.Write($"Stopping service...");
         ipcRead?.Close();
         spMon?.StopMonitoring();
         launcher.KillSp();
         namedIpc?.Dispose();
         cSocket?.Dispose();
         ISLogger.Exit();
     }catch (Exception) { }
 }
Пример #5
0
        public static void Stop()
        {
            if (!Running)
            {
                return;
            }

            if (MainSocket != null)
            {
                MainSocket.Dispose();
            }

            Running = false;
        }
Пример #6
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    ServerSocket?.Dispose();
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Пример #7
0
 /// <summary>
 /// This method stops connection tisth server, shutdown's server socket ass well as prevent reconnection by setting Reconnect and KeepConnected properties to false.
 /// </summary>
 public void Stop()
 {
     try
     {
         if (ServerSocket != null)
         {
             ServerSocket.Shutdown(SocketShutdown.Both);
             Thread.Sleep(100);
             ServerSocket.Close();
             ServerSocket.Dispose();
             ServerSocket = null;
         }
     }
     catch { }
 }
Пример #8
0
        /// <summary>
        /// Метод запускае прослушивание порт и возвращает сведение о запуске
        /// </summary>
        /// <returns>true - если сокет сервера создан и запущен</returns>
        private bool SetupServerSocket()
        {
            bool status = false;

            try
            {
                if (!IsListeningStatus)
                {
                    if (ServerSocket != null)
                    {
                        ServerSocket.Dispose();
                        ServerSocket = null;
                    }
                    // создаем сокет
                    ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                    {
                        ReceiveTimeout    = TimeoutReceive,
                        SendTimeout       = TimeoutSend,
                        ReceiveBufferSize = SizeBuffer,
                        SendBufferSize    = SizeBuffer
                    };
                    IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Port);
                    // Create a TCP/IP socket.
                    ServerSocket.Bind(localEndPoint);
                    // начинаем слушать порт
                    ServerSocket.Listen((int)SocketOptionName.MaxConnections);
                    status = true;
                }
                else
                {
                    CallErrorServer(ServerErrorType.WasListening, "The server has already been started earlier");
                }
            }
            catch (SocketException ex)
            {
                CallErrorServer(ServerErrorType.InitServerError, ex.Message);
            }
            catch (SecurityException ex)
            {
                CallErrorServer(ServerErrorType.SecurityError, ex.Message);
            }
            catch (Exception ex)
            {
                CallErrorServer(ServerErrorType.Other, ex.Message);
            }
            return(status);
        }
Пример #9
0
        private async void Run()
        {
            ServerSocket.Listen(200);

            while (!Exiting)
            {
                var client = await ServerSocket.AcceptAsync();

                var mqClient = new MessageQueueClient(client, OnMessage);

                Log.LogInformation("Client connected");

                Clients.Add(mqClient);

                mqClient.Start();
            }

            ServerSocket.Shutdown(SocketShutdown.Both);
            ServerSocket.Dispose();
        }
Пример #10
0
        private void StartConn()
        {
            if (ServerSocket != null)
            {
                ServerSocket.Close();
                ServerSocket.Dispose();
            }
            ServerSocket          = new Socket(AddressFamily.InterNetwork, SockType, ProtType);
            ServerSocket.Blocking = false;

            ConnectionTimer.Restart();
            receiveTimer.Restart();

            SocketCreated = true;

            //completely suppress the socket exception. There will always be an exception since the socket was set to non-blocking
            try
            {
                ServerSocket.Connect(IPaddress, Port);
            }
            catch { }
        }
Пример #11
0
        public void SendReboot()
        {
            while (RequestProccess.ThreadCount > 1)
            {
                Thread.Sleep(300);
                //wait...
            }

            ServerSocket.Close();
            ServerSocket.Dispose();
            ServerSocket = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            ServerSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
            ServerSocket.Listen(0);
            ServerSocket.BeginAccept(AcceptCallback, null);

            RebootRequest?.Invoke();
        }
Пример #12
0
 public void Dispose()
 {
     _cmdSocket?.Dispose();
 }
Пример #13
0
 /// <summary>
 /// Stops the listener and releases all of its resources.
 /// </summary>
 public void Dispose()
 {
     process = false;
     l.Dispose();
     lt.Wait();
 }