feature/separacao-gerenciadores #1

Merged
gustavo merged 31 commits from feature/separacao-gerenciadores into main 2026-09-30 18:34:54 -03:00
Showing only changes of commit 3efc59444f - Show all commits
+5
View File
@@ -35,6 +35,7 @@ public class SocketTCP extends Thread implements PeerListener {
private final ExecutorService connectionExecutor = Executors.newCachedThreadPool();
private final Map<InetAddress, TcpConnection> connections;
private ServerSocket serverSocket;
private InetAddress address;
private final MainWindow main;
@@ -54,6 +55,7 @@ public class SocketTCP extends Thread implements PeerListener {
connections = new ConcurrentHashMap<>();
try {
serverSocket = new ServerSocket(main.getPort());
address = InetAddress.getByName(InetAddress.getLocalHost().getHostAddress());
} catch (IOException ex) {
System.out.println("There is no socket connection. Sorry.");
System.out.println(ex);
@@ -72,6 +74,9 @@ public class SocketTCP extends Thread implements PeerListener {
*/
public void send(byte[] msg, InetAddress destinationAddress) {
try {
if (destinationAddress.equals(address)) {
throw new IllegalArgumentException("Destination address cannot be the same as the original address.");
}
TcpConnection connec tion;
synchronized (connections) {