This commit is contained in:
Mongolila-098
2026-04-28 13:35:30 +02:00
parent c480c4a831
commit d1bbc9fb28
29 changed files with 53 additions and 7 deletions

6
.classpath Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

17
.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>nanofiles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -160,6 +160,12 @@ public class NFController {
* servidor escucha conexiones de otros peers así como la lista de ficheros * servidor escucha conexiones de otros peers así como la lista de ficheros
* disponibles. * disponibles.
*/ */
//Comprobamos si ya estamos sirviendo
if (controllerPeer.getServerPort() != 0) {
System.err.println("* Ya existe un servidor de ficheros activo en el puerto " + controllerPeer.getServerPort());
break;
}
if (NanoFiles.testModeTCP) { if (NanoFiles.testModeTCP) {
controllerPeer.testTCPServer(); controllerPeer.testTCPServer();
} else { } else {

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -278,8 +278,13 @@ public class NFServer implements Runnable {
msgOut.writeMessageToOutputStream(dos); msgOut.writeMessageToOutputStream(dos);
} }
break; break;
default:
System.err.println("* [Servidor] Recibido opcode inesperado o inválido");
break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

Binary file not shown.

Binary file not shown.

View File

@@ -6,6 +6,7 @@ import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.SocketException;
import java.util.Map; import java.util.Map;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -115,21 +116,32 @@ public class DirectoryConnector {
DatagramPacket pktFromServer = new DatagramPacket(responseData, responseData.length); DatagramPacket pktFromServer = new DatagramPacket(responseData, responseData.length);
int intentos = 0; int intentos = 0;
boolean recibido = false; boolean recibido = false;
//Hay que configurar el timeout antes del bucle
try {
socket.setSoTimeout(TIMEOUT);
} catch (SocketException e) {
System.err.println("* Error configurando el timeout del socket UDP: " + e.getMessage());
return null;
}
while (intentos < MAX_NUMBER_OF_ATTEMPTS && !recibido) { while (intentos < MAX_NUMBER_OF_ATTEMPTS && !recibido) {
try { try {
socket.send(pktToServer); socket.send(pktToServer);
socket.setSoTimeout(TIMEOUT);
socket.receive(pktFromServer); socket.receive(pktFromServer);
recibido = true; recibido = true;
} catch (IOException e) { //excepciones tratadas
} catch (SocketTimeoutException e){
intentos++; intentos++;
if (intentos == MAX_NUMBER_OF_ATTEMPTS) { System.err.println("* Timeout. Reintentando... (" + intentos + "/" + MAX_NUMBER_OF_ATTEMPTS + ")");
System.err.println("DirectoryConnector.sendAndReceiveDatagrams: socket.receive()"); } catch (IOException e) {
System.exit(-1); System.err.println("* Error grave de I/O en UDP: " + e.getMessage());
} System.exit(-1);
} }
}
if (intentos == MAX_NUMBER_OF_ATTEMPTS) {
System.err.println("* El directorio no responde tras " + MAX_NUMBER_OF_ATTEMPTS + " intentos.");
System.exit(-1);
} }
String servResp = new String(responseData, 0, pktFromServer.getLength()); String servResp = new String(responseData, 0, pktFromServer.getLength());
response = servResp.getBytes(); response = servResp.getBytes();
System.out.println("Hemos recibido " + servResp); System.out.println("Hemos recibido " + servResp);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.