示例#1
0
 public void Dispose()
 {
     if (ServerThread.IsAlive)
     {
         ServerThread.Abort();
     }
 }
示例#2
0
文件: NTServer.cs 项目: OSandh/NTTCP
        private void Listen()
        {
            try
            {
                Listener = new TcpListener(IP, Port);
                Listener.Start();

                while (Run)
                {
                    // get current curson pos
                    int cursorTop  = Console.CursorTop;
                    int cursorLeft = Console.CursorLeft;

                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("Waiting for connection...");

                    // reset curson pos
                    Console.SetCursorPosition(cursorLeft, cursorTop);

                    TcpClient tcpC = Listener.AcceptTcpClient();

                    User user = RecieveUserData(tcpC.GetStream());

                    if (user != null)
                    {
                        NTClient client = new NTClient(this, tcpC, user);

                        ClientList.Add(client);

                        Console.SetCursorPosition(0, 1);
                        Console.WriteLine("{0} connected!", tcpC.Client.ToString());

                        // reset curson pos
                        Console.SetCursorPosition(cursorLeft, cursorTop);

                        if (ClientList.Count == 2)
                        {
                            PairClients();
                        }
                    }
                    else
                    {
                        Console.SetCursorPosition(0, 1);
                        Console.WriteLine("Client rejected. Could not resolve client user data...");
                        Console.SetCursorPosition(cursorLeft, cursorTop);
                        tcpC?.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Listener?.Stop();
                KillClients();
                ServerThread.Abort();
            }
        }
示例#3
0
        public void Dispose()
        {
            for (int i = 0; i < clientHandlers.Count; i++)
            {
                clientHandlers[i].Dispose();
            }

            serverSocket.Dispose();
            ServerThread.Abort();
            GC.SuppressFinalize(this);
        }
示例#4
0
        /// <summary>
        /// Stops the socket server.
        /// </summary>
        public void Stop()
        {
            if (TcpServer != null)
            {
                TcpServer.Stop();
                TcpServer = null;
            }

            State = InspectionEngineState.NotRunning;

            ServerThread.Abort();
        }
    private void OnApplicationQuit()
    {
        if (_client != null)
        {
            _client.close();
            _client.Abort();
        }

        if (_server != null)
        {
            _server.close();
            _server.Abort();
        }
    }
示例#6
0
        /// <summary>
        /// Stops the server if it is running
        /// </summary>
        public void Stop()
        {
            Status  = ServerStatus.Stopped;
            Enabled = false;

            // Disconnect all of the players
            ServerDirector.DisconnectAll();

            // Close our network connection
            Socket.Close();
            // Socket = null;

            // Kill the server thread
            ServerThread.Abort();
        }
        // Xử lý đóng Socket, Thread khi đóng Form
        private void P2PVideoCall_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!stoped)
            {
                try
                {
                    isSending = false;
                    server_sock.Close();
                    ServerThread.Abort();
                }
                catch (Exception) { }

                try
                {
                    capture.PreviewWindow = null;
                    if (capture != null)
                    {
                        capture.Stop();
                    }
                }
                catch (Exception) { }
            }
        }