mirror of
https://github.com/binlaab/nanofiles.git
synced 2026-07-01 13:47:41 +02:00
gg
This commit is contained in:
Binary file not shown.
BIN
es/um/redes/nanoFiles/udp/client/DirectoryConnector.class
Normal file
BIN
es/um/redes/nanoFiles/udp/client/DirectoryConnector.class
Normal file
Binary file not shown.
@@ -6,6 +6,7 @@ import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Map;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -115,21 +116,32 @@ public class DirectoryConnector {
|
||||
DatagramPacket pktFromServer = new DatagramPacket(responseData, responseData.length);
|
||||
int intentos = 0;
|
||||
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) {
|
||||
try {
|
||||
socket.send(pktToServer);
|
||||
socket.setSoTimeout(TIMEOUT);
|
||||
socket.receive(pktFromServer);
|
||||
recibido = true;
|
||||
} catch (IOException e) {
|
||||
//excepciones tratadas
|
||||
} catch (SocketTimeoutException e){
|
||||
intentos++;
|
||||
if (intentos == MAX_NUMBER_OF_ATTEMPTS) {
|
||||
System.err.println("DirectoryConnector.sendAndReceiveDatagrams: socket.receive()");
|
||||
System.exit(-1);
|
||||
}
|
||||
System.err.println("* Timeout. Reintentando... (" + intentos + "/" + MAX_NUMBER_OF_ATTEMPTS + ")");
|
||||
} catch (IOException e) {
|
||||
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());
|
||||
response = servResp.getBytes();
|
||||
System.out.println("Hemos recibido " + servResp);
|
||||
|
||||
Reference in New Issue
Block a user