Merge branch 'master' of https://gitlab2.istic.univ-rennes1.fr/tuvu/ipd-tp-2
This commit is contained in:
16
src/main/java/pr/tp2/udp/chat/ChatMulticast.java
Normal file
16
src/main/java/pr/tp2/udp/chat/ChatMulticast.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package pr.tp2.udp.chat;
|
||||
|
||||
public class ChatMulticast {
|
||||
|
||||
private static class Receiver implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Code de reception et affichage
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Lecture au clavier et envoie du message
|
||||
// Vous pouvez utiliser Scanner : https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Scanner.html
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package pr.tp2.udp.discovery;
|
||||
|
||||
public class Discovery {
|
||||
|
||||
public static void sendWhois(String id) {
|
||||
// Envoie un message Whois
|
||||
}
|
||||
|
||||
public static void sendLeaving(String id) {
|
||||
// Envoie un message Leaving
|
||||
}
|
||||
|
||||
public static void sendIAM(String id, String url) {
|
||||
// Envoie un message IAM
|
||||
}
|
||||
|
||||
public static void listenAndReply() {
|
||||
// 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":
|
||||
listenAndReply();
|
||||
break;
|
||||
case "iam":
|
||||
sendIAM(id, url);
|
||||
break;
|
||||
case "leaving":
|
||||
sendLeaving(id);
|
||||
break;
|
||||
case "whois":
|
||||
sendWhois(id);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Erreur de commande");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package pr.tp2.udp.discovery;
|
||||
|
||||
public class TestDiscovery {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Runnable listener = () -> {
|
||||
Discovery.listenAndReply();
|
||||
};
|
||||
new Thread(listener).start();
|
||||
|
||||
Discovery.sendWhois("051005022");
|
||||
Discovery.sendIAM("tftp", "127.0.0.1:6969");
|
||||
|
||||
Thread.sleep(10000);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,37 +3,33 @@ 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) throws IOException {
|
||||
int portTFTP = 7777;
|
||||
int portServeur= 6969;
|
||||
InetAddress ipServeur = InetAddress.getByName("localhost");
|
||||
try{
|
||||
// Attends sur le port 6969
|
||||
DatagramSocket dSocket = new DatagramSocket(portTFTP);
|
||||
int portServeur = 6969;
|
||||
DatagramSocket dSocket = null;
|
||||
try {
|
||||
// Attends sur le port 6969
|
||||
dSocket = new DatagramSocket(portServeur);
|
||||
// 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
|
||||
while (true) {
|
||||
byte[] buffer = new byte[512];
|
||||
// Reception du packet
|
||||
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(reception);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Décodage du packet
|
||||
decodeRequest(reception);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
dSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void affiche(byte[] bytes) {
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user