public void Dispose() { if (ServerThread.IsAlive) { ServerThread.Abort(); } }
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(); } }
public void Dispose() { for (int i = 0; i < clientHandlers.Count; i++) { clientHandlers[i].Dispose(); } serverSocket.Dispose(); ServerThread.Abort(); GC.SuppressFinalize(this); }
/// <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(); } }
/// <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) { } } }