Initial commit
This commit is contained in:
55
src/main/java/pr/tp2/udp/discovery/Discovery.java
Normal file
55
src/main/java/pr/tp2/udp/discovery/Discovery.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package pr.tp2.udp.discovery;
|
||||
|
||||
public class Discovery {
|
||||
|
||||
public static void handleWhois(String id) {
|
||||
// Envoie un message Whois
|
||||
}
|
||||
|
||||
public static void handleLeaving(String id) {
|
||||
// Envoie un message Leaving
|
||||
}
|
||||
|
||||
public static void handleIAM(String id, String url) {
|
||||
// Envoie un message IAM
|
||||
}
|
||||
|
||||
public static void handleListen() {
|
||||
// Ecoute et affiche les évennements IAM,LEAVING
|
||||
|
||||
// Réponds aux WHOIS si ID = ID
|
||||
// URL du service :
|
||||
String ID = "051005022";
|
||||
String URL = "https://istic.univ-rennes1.fr/";
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String cmd = args[0], url = null, id = null;
|
||||
if (args.length > 1) {
|
||||
id = args[1];
|
||||
}
|
||||
if (args.length == 3) {
|
||||
url = args[2];
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case "listen":
|
||||
handleListen();
|
||||
break;
|
||||
case "iam":
|
||||
handleIAM(id, url);
|
||||
break;
|
||||
case "leaving":
|
||||
handleLeaving(id);
|
||||
break;
|
||||
case "whois":
|
||||
handleWhois(id);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Erreur de commande");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/main/java/pr/tp2/udp/discovery/TestDiscovery.java
Normal file
17
src/main/java/pr/tp2/udp/discovery/TestDiscovery.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package pr.tp2.udp.discovery;
|
||||
|
||||
public class TestDiscovery {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Runnable listener = () -> {
|
||||
Discovery.handleListen();
|
||||
};
|
||||
new Thread(listener).start();
|
||||
|
||||
Discovery.handleWhois("051005022");
|
||||
Discovery.handleIAM("tftp", "127.0.0.1:6969");
|
||||
|
||||
Thread.sleep(10000);
|
||||
|
||||
}
|
||||
}
|
||||
35
src/main/java/pr/tp2/udp/tftp/TftpDecode.java
Normal file
35
src/main/java/pr/tp2/udp/tftp/TftpDecode.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package pr.tp2.udp.tftp;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
|
||||
public class TftpDecode {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Attends sur le port 6969
|
||||
|
||||
// Boucle
|
||||
|
||||
// Reception du packet
|
||||
DatagramPacket p = null;
|
||||
|
||||
// Affichage du packet
|
||||
|
||||
// Attention à ne pas afficher plus d'informations que nécessaire.
|
||||
|
||||
// Décodage du packet
|
||||
decodeRequest(p);
|
||||
}
|
||||
|
||||
public static void affiche(byte[] bytes) {
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
if (i % 16 == 0) {
|
||||
System.out.println("\n");
|
||||
}
|
||||
System.out.printf("%02x ", bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decodeRequest(DatagramPacket p) {
|
||||
System.out.printf("Type : %s, fichier : %s, mode %s", "RRQ", "test.txt", "ascii");
|
||||
}
|
||||
}
|
||||
51
src/main/java/pr/tp2/udp/tftp/TftpPutServeur.java
Normal file
51
src/main/java/pr/tp2/udp/tftp/TftpPutServeur.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package pr.tp2.udp.tftp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class TftpPutServeur {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Attends sur le port 6969
|
||||
|
||||
// Boucle
|
||||
|
||||
// Reception du packet
|
||||
DatagramPacket p = null;
|
||||
|
||||
// Affichage du packet
|
||||
|
||||
// Attention à ne pas afficher plus d'informations que nécessaire.
|
||||
|
||||
// Décodage du packet
|
||||
decodeRequest(p);
|
||||
|
||||
// Envoyer acquittement
|
||||
// sendAck(server, /***/);
|
||||
}
|
||||
|
||||
public static void sendAck(DatagramSocket server, short seqNumber, SocketAddress dstAddr) throws IOException {
|
||||
System.out.println("Send " + seqNumber + " to " + dstAddr);
|
||||
|
||||
// Construire le paquet avec les bonnes informations
|
||||
|
||||
// afficher le tableau de bytes envoyé
|
||||
|
||||
// Envoyer le paquet à la bonnes addresses
|
||||
}
|
||||
|
||||
public static void affiche(byte[] bytes) {
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
if (i % 16 == 0) {
|
||||
System.out.println("\n");
|
||||
}
|
||||
System.out.printf("%02x ", bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decodeRequest(DatagramPacket p) {
|
||||
System.out.printf("Type : %s, fichier : %s, mode %s", "RRQ", "test.txt", "ascii");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user