This commit is contained in:
tuvu
2025-02-25 10:08:26 +01:00
parent 6cf8242807
commit e704a6d370

View File

@@ -3,37 +3,33 @@ package pr.tp2.udp.tftp;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
public class TftpDecode { public class TftpDecode {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
int portTFTP = 7777; int portServeur = 6969;
int portServeur= 6969; DatagramSocket dSocket = null;
InetAddress ipServeur = InetAddress.getByName("localhost"); try {
try{ // Attends sur le port 6969
// Attends sur le port 6969 dSocket = new DatagramSocket(portServeur);
DatagramSocket dSocket = new DatagramSocket(portTFTP); // Boucle
while (true) {
byte[] buffer = new byte[21];
// Reception du packet
DatagramPacket reception = new DatagramPacket(buffer, buffer.length);
dSocket.receive(reception);
// Affichage du packet
affiche(buffer);
// Attention à ne pas afficher plus d'informations que nécessaire.
// Boucle // Décodage du packet
while (true) { decodeRequest(reception);
byte[] buffer = new byte[512]; }
// Reception du packet } catch (IOException e) {
DatagramPacket reception =new DatagramPacket(buffer, buffer.length); e.printStackTrace();
dSocket.receive(reception); } finally {
dSocket.close();
// Affichage du packet }
System.out.println(new String(buffer)); }
// Attention à ne pas afficher plus d'informations que nécessaire.
// Décodage du packet
decodeRequest(reception);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void affiche(byte[] bytes) { public static void affiche(byte[] bytes) {
for (int i = 0; i < bytes.length; i++) { for (int i = 0; i < bytes.length; i++) {