diff --git a/README.md b/README.md index 254e425..3fe04a6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,21 @@ ## Partie 1 : protocole TFTP ### Exercice 1 : Observation +Côté client +``` +tftp localhost 6969 +tftp> get test.html +put test.html +quit +Transfer timed out. +``` + +Côté serveur +``` +nc -u -l -p 6969 +test.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetasciitest.htmlnetascii +``` ### Exercice 2 : Décodage des requêtes. ### Exercice 3 : Acquitter diff --git a/images/p1_ex1_tftp.pcapng b/images/p1_ex1_tftp.pcapng new file mode 100755 index 0000000..482722d Binary files /dev/null and b/images/p1_ex1_tftp.pcapng differ diff --git a/src/main/java/pr/tp2/udp/tftp/TftpDecode.java b/src/main/java/pr/tp2/udp/tftp/TftpDecode.java index 95ac82b..122efbd 100644 --- a/src/main/java/pr/tp2/udp/tftp/TftpDecode.java +++ b/src/main/java/pr/tp2/udp/tftp/TftpDecode.java @@ -1,23 +1,38 @@ package pr.tp2.udp.tftp; +import java.io.IOException; import java.net.DatagramPacket; - +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.ServerSocket; public class TftpDecode { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { + int portTFTP = 7777; + int portServeur= 6969; + InetAddress ipServeur = InetAddress.getByName("localhost"); + try{ // Attends sur le port 6969 + DatagramSocket dSocket = new DatagramSocket(portTFTP); // Boucle - + while (true) { + byte[] buffer = new byte[512]; // Reception du packet - DatagramPacket p = null; + DatagramPacket reception =new DatagramPacket(buffer, buffer.length); + dSocket.receive(reception); // Affichage du packet - + System.out.println(new String(buffer)); + // Attention à ne pas afficher plus d'informations que nécessaire. // Décodage du packet - decodeRequest(p); + decodeRequest(reception); + } + } catch (IOException e) { + e.printStackTrace(); + } } public static void affiche(byte[] bytes) {