Ejemplo n.º 1
0
 public void Dispose()
 {
     if (ServerThread.IsAlive)
     {
         ServerThread.Abort();
     }
 }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        public void Dispose()
        {
            for (int i = 0; i < clientHandlers.Count; i++)
            {
                clientHandlers[i].Dispose();
            }

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

            State = InspectionEngineState.NotRunning;

            ServerThread.Abort();
        }
Ejemplo n.º 5
0
    private void OnApplicationQuit()
    {
        if (_client != null)
        {
            _client.close();
            _client.Abort();
        }

        if (_server != null)
        {
            _server.close();
            _server.Abort();
        }
    }
Ejemplo n.º 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();
        }
Ejemplo n.º 7
0
        // 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) { }
            }
        }