-
Notifications
You must be signed in to change notification settings - Fork 0
Update from task 43d59903-2f84-4a85-a7f2-b01b4c082ed0 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ``` | ||
| # Compiled Java classes | ||
| *.class | ||
|
|
||
| # Build directory | ||
| bin/ | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| package TCP; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.*; | ||
| import java.awt.event.*; | ||
| import java.io.*; | ||
| import java.net.*; | ||
|
|
||
| public class TCPClientGUI extends JFrame { | ||
| private JTextField hostField; | ||
| private JSpinner portSpinner; | ||
| private JTextArea messageArea; | ||
| private JTextField inputField; | ||
| private JButton connectButton; | ||
| private JButton sendButton; | ||
| private Socket socket; | ||
| private PrintWriter out; | ||
| private BufferedReader in; | ||
| private boolean connected = false; | ||
|
|
||
| public TCPClientGUI() { | ||
| super("TCP Client GUI"); | ||
| setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| setSize(600, 500); | ||
| setLocationRelativeTo(null); | ||
|
|
||
| // Create components | ||
| JPanel topPanel = new JPanel(new GridBagLayout()); | ||
| GridBagConstraints gbc = new GridBagConstraints(); | ||
| gbc.insets = new Insets(5, 5, 5, 5); | ||
| gbc.anchor = GridBagConstraints.WEST; | ||
|
|
||
| topPanel.add(new JLabel("Host:"), gbc); | ||
| gbc.gridx = 1; | ||
| gbc.weightx = 1.0; | ||
| gbc.fill = GridBagConstraints.HORIZONTAL; | ||
| hostField = new JTextField("localhost", 15); | ||
| topPanel.add(hostField, gbc); | ||
|
|
||
| gbc.gridx = 2; | ||
| gbc.weightx = 0; | ||
| gbc.fill = GridBagConstraints.NONE; | ||
| topPanel.add(new JLabel("Port:"), gbc); | ||
| gbc.gridx = 3; | ||
| portSpinner = new JSpinner(new SpinnerNumberModel(5000, 1, 65535, 1)); | ||
| topPanel.add(portSpinner, gbc); | ||
|
|
||
| gbc.gridx = 4; | ||
| connectButton = new JButton("Connect"); | ||
| connectButton.addActionListener(e -> toggleConnection()); | ||
| topPanel.add(connectButton, gbc); | ||
|
|
||
| // Message display area | ||
| messageArea = new JTextArea(); | ||
| messageArea.setEditable(false); | ||
| messageArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); | ||
| JScrollPane scrollPane = new JScrollPane(messageArea); | ||
| scrollPane.setPreferredSize(new Dimension(0, 300)); | ||
|
|
||
| // Input panel | ||
| JPanel inputPanel = new JPanel(new BorderLayout()); | ||
| inputField = new JTextField(); | ||
| inputField.setEnabled(false); | ||
| inputField.addActionListener(e -> sendMessage()); | ||
| sendButton = new JButton("Send"); | ||
| sendButton.setEnabled(false); | ||
| sendButton.addActionListener(e -> sendMessage()); | ||
|
|
||
| inputPanel.add(inputField, BorderLayout.CENTER); | ||
| inputPanel.add(sendButton, BorderLayout.EAST); | ||
|
|
||
| // Layout | ||
| setLayout(new BorderLayout()); | ||
| add(topPanel, BorderLayout.NORTH); | ||
| add(scrollPane, BorderLayout.CENTER); | ||
| add(inputPanel, BorderLayout.SOUTH); | ||
|
|
||
| setVisible(true); | ||
| } | ||
|
|
||
| private void toggleConnection() { | ||
| if (!connected) { | ||
| connect(); | ||
| } else { | ||
| disconnect(); | ||
| } | ||
| } | ||
|
|
||
| private void connect() { | ||
| String host = hostField.getText().trim(); | ||
| int port = (Integer) portSpinner.getValue(); | ||
|
|
||
| try { | ||
| socket = new Socket(host, port); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "TCPClientGUI.java" -type fRepository: Bendz07/TCP_UDP-Java Length of output: 91 🏁 Script executed: cat -n "src/TCP/TCPClientGUI.java" | head -150Repository: Bendz07/TCP_UDP-Java Length of output: 5963 🏁 Script executed: tail -50 "src/TCP/TCPClientGUI.java"Repository: Bendz07/TCP_UDP-Java Length of output: 1544 Move socket connection to a background thread with a finite timeout to prevent GUI freezing. Line 94 executes Refactor the connection logic into a
For example, use 🤖 Prompt for AI Agents |
||
| out = new PrintWriter(socket.getOutputStream(), true); | ||
| in = new BufferedReader(new InputStreamReader(socket.getInputStream())); | ||
|
|
||
| connected = true; | ||
| connectButton.setText("Disconnect"); | ||
| inputField.setEnabled(true); | ||
| sendButton.setEnabled(true); | ||
| hostField.setEnabled(false); | ||
| portSpinner.setEnabled(false); | ||
| messageArea.append("Connected to server at " + host + ":" + port + "\n"); | ||
|
|
||
| // Start reader thread | ||
| new Thread(this::readFromServer).start(); | ||
|
|
||
| } catch (IOException e) { | ||
| JOptionPane.showMessageDialog(this, "Failed to connect: " + e.getMessage(), | ||
| "Connection Error", JOptionPane.ERROR_MESSAGE); | ||
| disconnect(); | ||
| } | ||
| } | ||
|
|
||
| private void disconnect() { | ||
| connected = false; | ||
| connectButton.setText("Connect"); | ||
| inputField.setEnabled(false); | ||
| sendButton.setEnabled(false); | ||
| hostField.setEnabled(true); | ||
| portSpinner.setEnabled(true); | ||
| messageArea.append("Disconnected from server\n"); | ||
|
|
||
| try { | ||
| if (socket != null && !socket.isClosed()) { | ||
| socket.close(); | ||
| } | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| private void readFromServer() { | ||
| String line; | ||
| try { | ||
| while (connected && (line = in.readLine()) != null) { | ||
| String finalLine = line; | ||
| SwingUtilities.invokeLater(() -> messageArea.append("Server: " + finalLine + "\n")); | ||
| } | ||
| } catch (IOException e) { | ||
| if (connected) { | ||
| SwingUtilities.invokeLater(() -> { | ||
| messageArea.append("Connection lost: " + e.getMessage() + "\n"); | ||
| disconnect(); | ||
| }); | ||
|
Comment on lines
+134
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "TCPClientGUI.java" -type fRepository: Bendz07/TCP_UDP-Java Length of output: 91 🏁 Script executed: git ls-files | grep -i tcpRepository: Bendz07/TCP_UDP-Java Length of output: 209 🏁 Script executed: cat -n ./src/TCP/TCPClientGUI.javaRepository: Bendz07/TCP_UDP-Java Length of output: 6441 Reset only the connection owned by this reader.
Pass socket and reader as method parameters to give each thread its own snapshot, and check socket identity before performing disconnect operations: Proposed fix- new Thread(this::readFromServer).start();
+ Socket clientSocket = socket;
+ BufferedReader reader = in;
+ new Thread(() -> readFromServer(clientSocket, reader), "tcp-client-reader").start();- private void readFromServer() {
+ private void readFromServer(Socket clientSocket, BufferedReader reader) {
String line;
+ boolean shouldDisconnect = false;
try {
- while (connected && (line = in.readLine()) != null) {
+ while (connected && socket == clientSocket && (line = reader.readLine()) != null) {
String finalLine = line;
SwingUtilities.invokeLater(() -> messageArea.append("Server: " + finalLine + "\n"));
}
+ shouldDisconnect = connected && socket == clientSocket;
} catch (IOException e) {
- if (connected) {
+ shouldDisconnect = connected && socket == clientSocket;
+ if (shouldDisconnect) {
SwingUtilities.invokeLater(() -> {
messageArea.append("Connection lost: " + e.getMessage() + "\n");
disconnect();
});
}
+ return;
+ }
+
+ if (shouldDisconnect) {
+ SwingUtilities.invokeLater(() -> {
+ messageArea.append("Connection closed by server\n");
+ disconnect();
+ });
}
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| } | ||
|
|
||
| private void sendMessage() { | ||
| String message = inputField.getText().trim(); | ||
| if (!message.isEmpty() && connected) { | ||
| out.println(message); | ||
| messageArea.append("You: " + message + "\n"); | ||
|
Comment on lines
+153
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: fd TCPClientGUI.javaRepository: Bendz07/TCP_UDP-Java Length of output: 89 🏁 Script executed: cat -n src/TCP/TCPClientGUI.java | sed -n '150,160p'Repository: Bendz07/TCP_UDP-Java Length of output: 465 🏁 Script executed: cat -n src/TCP/TCPClientGUI.java | grep -n "PrintWriter\|out\s*=" | head -20Repository: Bendz07/TCP_UDP-Java Length of output: 179 🏁 Script executed: cat -n src/TCP/TCPClientGUI.java | sed -n '1,30p'Repository: Bendz07/TCP_UDP-Java Length of output: 1140 🏁 Script executed: cat -n src/TCP/TCPClientGUI.java | sed -n '85,105p'Repository: Bendz07/TCP_UDP-Java Length of output: 930 🏁 Script executed: cat -n src/TCP/TCPClientGUI.java | sed -n '110,140p'Repository: Bendz07/TCP_UDP-Java Length of output: 1282 Check write failures before showing the message as sent.
Proposed fix String message = inputField.getText().trim();
if (!message.isEmpty() && connected) {
- out.println(message);
- messageArea.append("You: " + message + "\n");
- inputField.setText("");
+ try {
+ out.println(message);
+ if (out.checkError()) {
+ throw new IOException("Failed to write to server");
+ }
+ messageArea.append("You: " + message + "\n");
+ inputField.setText("");
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(this, "Failed to send: " + e.getMessage(),
+ "Send Error", JOptionPane.ERROR_MESSAGE);
+ disconnect();
+ }🤖 Prompt for AI Agents |
||
| inputField.setText(""); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| SwingUtilities.invokeLater(TCPClientGUI::new); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,133 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| package TCP; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import javax.swing.*; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.awt.*; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.*; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.net.*; | ||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public class TCPServerGUI extends JFrame { | ||||||||||||||||||||||||||||||||||||||||||||||
| private JSpinner portSpinner; | ||||||||||||||||||||||||||||||||||||||||||||||
| private JButton startButton; | ||||||||||||||||||||||||||||||||||||||||||||||
| private JTextArea logArea; | ||||||||||||||||||||||||||||||||||||||||||||||
| private ServerSocket serverSocket; | ||||||||||||||||||||||||||||||||||||||||||||||
| private AtomicBoolean running = new AtomicBoolean(false); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public TCPServerGUI() { | ||||||||||||||||||||||||||||||||||||||||||||||
| super("TCP Server GUI"); | ||||||||||||||||||||||||||||||||||||||||||||||
| setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||||||||||||||||||||||||||||||||||||||||||||
| setSize(600, 500); | ||||||||||||||||||||||||||||||||||||||||||||||
| setLocationRelativeTo(null); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Top panel with port and start button | ||||||||||||||||||||||||||||||||||||||||||||||
| JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); | ||||||||||||||||||||||||||||||||||||||||||||||
| topPanel.add(new JLabel("Port:")); | ||||||||||||||||||||||||||||||||||||||||||||||
| portSpinner = new JSpinner(new SpinnerNumberModel(5000, 1, 65535, 1)); | ||||||||||||||||||||||||||||||||||||||||||||||
| topPanel.add(portSpinner); | ||||||||||||||||||||||||||||||||||||||||||||||
| startButton = new JButton("Start Server"); | ||||||||||||||||||||||||||||||||||||||||||||||
| startButton.addActionListener(e -> toggleServer()); | ||||||||||||||||||||||||||||||||||||||||||||||
| topPanel.add(startButton); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Log area | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea = new JTextArea(); | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.setEditable(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); | ||||||||||||||||||||||||||||||||||||||||||||||
| JScrollPane scrollPane = new JScrollPane(logArea); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Layout | ||||||||||||||||||||||||||||||||||||||||||||||
| setLayout(new BorderLayout()); | ||||||||||||||||||||||||||||||||||||||||||||||
| add(topPanel, BorderLayout.NORTH); | ||||||||||||||||||||||||||||||||||||||||||||||
| add(scrollPane, BorderLayout.CENTER); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| setVisible(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private void toggleServer() { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!running.get()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| startServer(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| stopServer(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private void startServer() { | ||||||||||||||||||||||||||||||||||||||||||||||
| int port = (Integer) portSpinner.getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| serverSocket = new ServerSocket(port); | ||||||||||||||||||||||||||||||||||||||||||||||
| running.set(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| startButton.setText("Stop Server"); | ||||||||||||||||||||||||||||||||||||||||||||||
| portSpinner.setEnabled(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.append("TCP Server started on port " + port + "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Accept clients in a separate thread | ||||||||||||||||||||||||||||||||||||||||||||||
| new Thread(this::acceptClients).start(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "TCPServerGUI.java" -type fRepository: Bendz07/TCP_UDP-Java Length of output: 91 🏁 Script executed: cat -n src/TCP/TCPServerGUI.javaRepository: Bendz07/TCP_UDP-Java Length of output: 5348 Bind accept loop to specific ServerSocket instance and update log area safely from EDT. Two issues in
Proposed fix- new Thread(this::acceptClients).start();
+ ServerSocket boundServerSocket = serverSocket;
+ new Thread(() -> acceptClients(boundServerSocket), "tcp-server-accept").start();- private void acceptClients() {
- while (running.get()) {
+ private void acceptClients(ServerSocket boundServerSocket) {
+ while (running.get() && !boundServerSocket.isClosed()) {
try {
- Socket clientSocket = serverSocket.accept();
- logArea.append("Client connected: " + clientSocket.getInetAddress() + "\n");
+ Socket clientSocket = boundServerSocket.accept();
+ SwingUtilities.invokeLater(() ->
+ logArea.append("Client connected: " + clientSocket.getInetAddress() + "\n"));
// Handle each client in a separate thread
new Thread(() -> handleClient(clientSocket)).start();
} catch (IOException e) {
if (running.get()) {
- logArea.append("Error accepting client: " + e.getMessage() + "\n");
+ SwingUtilities.invokeLater(() ->
+ logArea.append("Error accepting client: " + e.getMessage() + "\n"));
}
}
}
}📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| JOptionPane.showMessageDialog(this, "Failed to start server: " + e.getMessage(), | ||||||||||||||||||||||||||||||||||||||||||||||
| "Server Error", JOptionPane.ERROR_MESSAGE); | ||||||||||||||||||||||||||||||||||||||||||||||
| stopServer(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private void acceptClients() { | ||||||||||||||||||||||||||||||||||||||||||||||
| while (running.get()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| Socket clientSocket = serverSocket.accept(); | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.append("Client connected: " + clientSocket.getInetAddress() + "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Handle each client in a separate thread | ||||||||||||||||||||||||||||||||||||||||||||||
| new Thread(() -> handleClient(clientSocket)).start(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (running.get()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.append("Error accepting client: " + e.getMessage() + "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+76
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "TCPServerGUI.java" -type fRepository: Bendz07/TCP_UDP-Java Length of output: 91 🏁 Script executed: cat -n ./src/TCP/TCPServerGUI.java | head -100Repository: Bendz07/TCP_UDP-Java Length of output: 4225 🏁 Script executed: rg "logArea\.append" ./src/TCP/TCPServerGUI.java -nRepository: Bendz07/TCP_UDP-Java Length of output: 598 🏁 Script executed: cat -n ./src/TCP/TCPServerGUI.java | tail -30Repository: Bendz07/TCP_UDP-Java Length of output: 1116 Route accept-loop log updates through the EDT. Lines 76 and 83 update Proposed fix- logArea.append("Client connected: " + clientSocket.getInetAddress() + "\n");
+ SwingUtilities.invokeLater(() ->
+ logArea.append("Client connected: " + clientSocket.getInetAddress() + "\n"));
...
if (running.get()) {
- logArea.append("Error accepting client: " + e.getMessage() + "\n");
+ SwingUtilities.invokeLater(() ->
+ logArea.append("Error accepting client: " + e.getMessage() + "\n"));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private void handleClient(Socket clientSocket) { | ||||||||||||||||||||||||||||||||||||||||||||||
| try (BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | ||||||||||||||||||||||||||||||||||||||||||||||
| PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| String message; | ||||||||||||||||||||||||||||||||||||||||||||||
| while ((message = in.readLine()) != null) { | ||||||||||||||||||||||||||||||||||||||||||||||
| String finalMessage = message; | ||||||||||||||||||||||||||||||||||||||||||||||
| SwingUtilities.invokeLater(() -> | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.append("Received from " + clientSocket.getInetAddress() + ": " + finalMessage + "\n")); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| String response = "Echo: " + message; | ||||||||||||||||||||||||||||||||||||||||||||||
| out.println(response); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| SwingUtilities.invokeLater(() -> | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.append("Client disconnected: " + clientSocket.getInetAddress() + "\n")); | ||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| clientSocket.close(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| e.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| private void stopServer() { | ||||||||||||||||||||||||||||||||||||||||||||||
| running.set(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| startButton.setText("Start Server"); | ||||||||||||||||||||||||||||||||||||||||||||||
| portSpinner.setEnabled(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| logArea.append("TCP Server stopped\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (serverSocket != null && !serverSocket.isClosed()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| serverSocket.close(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+115
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "TCPServerGUI.java" | head -20Repository: Bendz07/TCP_UDP-Java Length of output: 91 🏁 Script executed: cat -n ./src/TCP/TCPServerGUI.javaRepository: Bendz07/TCP_UDP-Java Length of output: 5348 Close all active client sockets when stopping the server. When The proposed fix correctly addresses this by:
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| e.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||||||||||||||||||||||||||||||||
| SwingUtilities.invokeLater(TCPServerGUI::new); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove accidental backticks from
.gitignore.Line 1 and Line 7 appear to contain literal `````` entries, which look unintended and add noise to ignore rules.
Suggested cleanup
Also applies to: 7-7
🤖 Prompt for AI Agents