package messages, changement comm
This commit is contained in:
parent
13ca8bb0c0
commit
7a4d831d56
11 changed files with 282 additions and 116 deletions
|
@ -1,5 +1,6 @@
|
||||||
package communication;
|
package communication;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -39,35 +40,30 @@ public class Communication extends Thread{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
protected static int getIndexFromIP(InetAddress ip) {
|
||||||
//Combiner add et change
|
for(int i=0; i < Communication.users.size() ; i++) {
|
||||||
protected static synchronized void addUser(List<String> datas) throws UnknownHostException {
|
if(Communication.users.get(i).getIp().equals(ip)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
String idClient = datas.get(0);
|
|
||||||
String pseudoClient = datas.get(1);
|
|
||||||
String clientAddress = datas.get(2);
|
|
||||||
|
|
||||||
if (!Communication.containsUserFromID(idClient)) {
|
protected static synchronized void addUser(String idClient, String pseudoClient, InetAddress ipClient) throws UnknownHostException {
|
||||||
Communication.users.add(new Utilisateur(idClient, pseudoClient, clientAddress));
|
Communication.users.add(new Utilisateur(idClient, pseudoClient, ipClient));
|
||||||
VueStandard.userList.addElement(pseudoClient);
|
VueStandard.userList.addElement(pseudoClient);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected static synchronized void changePseudoUser(List<String> datas) {
|
protected static synchronized void changePseudoUser(String idClient, String pseudoClient, InetAddress ipClient) {
|
||||||
String idClient = datas.get(0);
|
|
||||||
String pseudoClient = datas.get(1);
|
|
||||||
int index = Communication.getIndexFromID(idClient);
|
int index = Communication.getIndexFromID(idClient);
|
||||||
// System.out.println(index);
|
|
||||||
if(index != -1) {
|
|
||||||
Communication.users.get(index).setPseudo(pseudoClient);
|
Communication.users.get(index).setPseudo(pseudoClient);
|
||||||
VueStandard.userList.set(index, pseudoClient);
|
VueStandard.userList.set(index, pseudoClient);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected static synchronized void removeUser(List<String> datas) {
|
|
||||||
String idClient = datas.get(0);
|
protected static synchronized void removeUser(String idClient, String pseudoClient,InetAddress ipClient) {
|
||||||
int index = Communication.getIndexFromID(idClient);
|
int index = Communication.getIndexFromIP(ipClient);
|
||||||
//System.out.println(index);
|
|
||||||
if( index != -1) {
|
if( index != -1) {
|
||||||
Communication.users.remove(index);
|
Communication.users.remove(index);
|
||||||
VueStandard.userList.remove(index);
|
VueStandard.userList.remove(index);
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import main.Utilisateur;
|
import main.Utilisateur;
|
||||||
|
import messages.*;
|
||||||
|
|
||||||
|
|
||||||
public class CommunicationUDP extends Communication {
|
public class CommunicationUDP extends Communication {
|
||||||
|
|
||||||
|
@ -36,64 +38,63 @@ public class CommunicationUDP extends Communication {
|
||||||
|
|
||||||
public void sendMessageConnecte() throws UnknownHostException, IOException {
|
public void sendMessageConnecte() throws UnknownHostException, IOException {
|
||||||
for(int port : this.portOthers) {
|
for(int port : this.portOthers) {
|
||||||
this.client.sendMessageUDP_local("first_connection", port, InetAddress.getLocalHost());
|
try {
|
||||||
|
this.client.sendMessageUDP_local(new MessageSysteme(Message.TypeMessage.JE_SUIS_CONNECTE), port, InetAddress.getLocalHost());
|
||||||
|
} catch (MauvaisTypeMessageException e) {/*Si ça marche pas essayer là*/}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send the message "add,id,pseudo" to localhost on all the ports in
|
// Send the message "add,id,pseudo" to localhost on all the ports in
|
||||||
// "portOthers"
|
// "portOthers"
|
||||||
// This allows the receivers' agent (portOthers) to create an entry with the
|
// This allows the receivers' agent (portOthers) to create or modify an entry with the
|
||||||
// data of this agent
|
// data of this agent
|
||||||
public void sendMessageAdd() throws UnknownHostException, IOException {
|
//Typically used to notify of a name change
|
||||||
this.sendIDPseudo_local("add");
|
public void sendMessageInfoPseudo() throws UnknownHostException, IOException {
|
||||||
|
|
||||||
|
Utilisateur self = Utilisateur.getSelf();
|
||||||
|
|
||||||
|
String pseudoSelf =self.getPseudo();
|
||||||
|
String idSelf = self.getId();
|
||||||
|
|
||||||
|
Message msout = null;
|
||||||
|
try {
|
||||||
|
msout = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, pseudoSelf, idSelf);
|
||||||
|
for(int port : this.portOthers) {
|
||||||
|
this.client.sendMessageUDP_local(msout, port, InetAddress.getLocalHost());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageAdd(ArrayList<Integer> portServers) throws UnknownHostException, IOException {
|
|
||||||
this.sendIDPseudo_local("add", portServers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the message "modify,id,pseudo" to localhost on all the ports in
|
//Same, but on only one port
|
||||||
// "portOthers"
|
//Typically used to give your current name and id to a newly arrived host
|
||||||
// This allows the receivers' agent (portOthers) to update the entry
|
public void sendMessageInfoPseudo(int portOther) throws UnknownHostException, IOException {
|
||||||
// corresponding to this agent
|
|
||||||
public void sendMessageModify() throws UnknownHostException, IOException {
|
Utilisateur self = Utilisateur.getSelf();
|
||||||
this.sendIDPseudo_local("modify");
|
try {
|
||||||
|
Message msout = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, self.getPseudo(), self.getId());
|
||||||
|
this.client.sendMessageUDP_local(msout, portOther, InetAddress.getLocalHost());
|
||||||
|
} catch (MauvaisTypeMessageException e) {e.printStackTrace();}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send the message "del,id,pseudo" to localhost on all the ports in
|
// Send the message "del,id,pseudo" to localhost on all the ports in
|
||||||
// "portOthers"
|
// "portOthers"
|
||||||
// This allows the receivers' agent (portOthers) to delete the entry
|
// This allows the receivers' agent (portOthers) to delete the entry
|
||||||
// corresponding to this agent
|
// corresponding to this agent
|
||||||
public void sendMessageDelete() throws UnknownHostException, IOException {
|
public void sendMessageDelete() throws UnknownHostException, IOException {
|
||||||
this.sendIDPseudo_local("del");
|
for(int port : this.portOthers) {
|
||||||
}
|
try {
|
||||||
|
this.client.sendMessageUDP_local(new MessageSysteme(Message.TypeMessage.JE_SUIS_DECONNECTE), port, InetAddress.getLocalHost());
|
||||||
// Private function to create the message "[prefix],id,pseudo"
|
} catch (MauvaisTypeMessageException e) {/*Si ça marche pas essayer là*/}
|
||||||
// and send it to localhost on all the ports in "portOthers"
|
|
||||||
private void sendIDPseudo_local(String prefixe, ArrayList<Integer> portServers) throws UnknownHostException, IOException {
|
|
||||||
Utilisateur self = Utilisateur.getSelf();
|
|
||||||
String idSelf = self.getId();
|
|
||||||
String pseudoSelf = self.getPseudo();
|
|
||||||
|
|
||||||
if (!pseudoSelf.equals("")) {
|
|
||||||
|
|
||||||
String message = prefixe + "," + idSelf + "," + pseudoSelf;
|
|
||||||
// A modifier pour créer un objet de type Message
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
for (int port : portServers) {
|
|
||||||
this.client.sendMessageUDP_local(message, port, InetAddress.getLocalHost());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
//Pas encore adapte message
|
||||||
|
|
||||||
private void sendIDPseudo_local(String prefixe) throws UnknownHostException, IOException {
|
|
||||||
this.sendIDPseudo_local(prefixe, this.portOthers);
|
|
||||||
}
|
|
||||||
|
|
||||||
// private void sendIDPseudo_broadcast(String prefixe) throws UnknownHostException, IOException {
|
// private void sendIDPseudo_broadcast(String prefixe) throws UnknownHostException, IOException {
|
||||||
// Utilisateur self = Utilisateur.getSelf();
|
// Utilisateur self = Utilisateur.getSelf();
|
||||||
// String idSelf = self.getId();
|
// String idSelf = self.getId();
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import messages.*;
|
||||||
|
|
||||||
public class UDPClient {
|
public class UDPClient {
|
||||||
|
|
||||||
private DatagramSocket sockUDP;
|
private DatagramSocket sockUDP;
|
||||||
|
@ -22,19 +24,17 @@ public class UDPClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Send a string message to the specified port on localhost
|
//Send a message casted as string to the specified port on localhost
|
||||||
protected void sendMessageUDP_local(String message, int port, InetAddress clientAddress) throws IOException {
|
protected void sendMessageUDP_local(Message message, int port, InetAddress clientAddress) throws IOException {
|
||||||
|
String messageString=message.toString();
|
||||||
//A modifier, faire passer un type Message en paramètre
|
DatagramPacket outpacket = new DatagramPacket(messageString.getBytes(), messageString.length(), clientAddress, port);
|
||||||
//puis écrire les instructions pour envoyer un Message à traver la socket
|
|
||||||
|
|
||||||
DatagramPacket outpacket = new DatagramPacket(message.getBytes(), message.length(), clientAddress, port);
|
|
||||||
this.sockUDP.send(outpacket);
|
this.sockUDP.send(outpacket);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected void sendMessageUDP_broadcast(String message, int port) throws IOException{
|
// protected void sendMessageUDP_broadcast(String message, int port) throws IOException{
|
||||||
// DatagramPacket outpacket = new DatagramPacket(message.getBytes(), message.length(), this.broadcast, port);
|
// String messageString=message.toString();
|
||||||
|
// DatagramPacket outpacket = new DatagramPacket(messageString.getBytes(), messageString.length(), this.broadcast, port);
|
||||||
// this.sockUDP.send(outpacket);
|
// this.sockUDP.send(outpacket);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.net.SocketException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import messages.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class UDPServer extends Thread {
|
public class UDPServer extends Thread {
|
||||||
|
@ -26,52 +28,44 @@ public class UDPServer extends Thread {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length);
|
||||||
this.sockUDP.receive(inPacket);
|
this.sockUDP.receive(inPacket);
|
||||||
String msg = new String(inPacket.getData(), 0, inPacket.getLength());
|
String msgString = new String(inPacket.getData(), 0, inPacket.getLength());
|
||||||
|
Message msg = Message.stringToMessage(msgString);
|
||||||
|
|
||||||
if (msg.equals("first_connection")) {
|
switch(msg.getTypeMessage()) {
|
||||||
|
case JE_SUIS_CONNECTE :
|
||||||
//System.out.println("first co");
|
//System.out.println("first co");
|
||||||
ArrayList<Integer> portClient = new ArrayList<Integer>();
|
int portClient = inPacket.getPort();
|
||||||
portClient.add(inPacket.getPort()+1);
|
int portServer = portClient+1;
|
||||||
this.commUDP.sendMessageAdd(portClient);
|
|
||||||
|
|
||||||
} else if (msg.contains("add,")) {
|
this.commUDP.sendMessageInfoPseudo(portServer);
|
||||||
//System.out.println("add");
|
break;
|
||||||
ArrayList<String> datas = this.getDatas(inPacket);
|
|
||||||
Communication.addUser(datas);
|
|
||||||
|
|
||||||
} else if (msg.contains("modify,")) {
|
case INFO_PSEUDO :
|
||||||
ArrayList<String> datas = this.getDatas(inPacket);
|
|
||||||
Communication.changePseudoUser(datas);
|
|
||||||
|
|
||||||
} else if (msg.contains("del,")) {
|
if (Communication.containsUserFromID(((MessageSysteme) msg).getId())) {
|
||||||
ArrayList<String> datas = this.getDatas(inPacket);
|
Communication.changePseudoUser(((MessageSysteme) msg).getId(), ((MessageSysteme) msg).getPseudo(), inPacket.getAddress());
|
||||||
Communication.removeUser(datas);
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Communication.addUser(((MessageSysteme) msg).getId(), ((MessageSysteme) msg).getPseudo(), inPacket.getAddress());
|
||||||
|
System.out.println(((MessageSysteme) msg).getId()+", "+((MessageSysteme) msg).getPseudo());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JE_SUIS_DECONNECTE :
|
||||||
|
Communication.removeUser( ((MessageSysteme) msg).getId() , ((MessageSysteme) msg).getPseudo(), inPacket.getAddress() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default : //Others types of messages are ignored because they are supposed to be transmitted by TCP and not UDP
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("receive exception");
|
System.out.println("receive exception");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<String> getDatas(DatagramPacket inPacket) {
|
|
||||||
//Message
|
|
||||||
//
|
|
||||||
|
|
||||||
String msg = new String(inPacket.getData(), 0, inPacket.getLength());
|
|
||||||
String tmp[] = msg.split(",");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ArrayList<String> datas = new ArrayList<String>(Arrays.asList(tmp));
|
|
||||||
datas.remove(0);
|
|
||||||
datas.add(inPacket.getAddress().toString());
|
|
||||||
|
|
||||||
return datas;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class ControleurStandard implements ActionListener, ListSelectionListener
|
||||||
this.vue = vue;
|
this.vue = vue;
|
||||||
this.commUDP = new CommunicationUDP(portClient,portServer, portsOther);
|
this.commUDP = new CommunicationUDP(portClient,portServer, portsOther);
|
||||||
this.commUDP.sendMessageConnecte();
|
this.commUDP.sendMessageConnecte();
|
||||||
this.commUDP.sendMessageAdd();
|
this.commUDP.sendMessageInfoPseudo();
|
||||||
this.etatModif = EtatModif.TERMINE;
|
this.etatModif = EtatModif.TERMINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class ControleurStandard implements ActionListener, ListSelectionListener
|
||||||
Utilisateur.getSelf().setPseudo(this.vue.getDisplayedPseudo());
|
Utilisateur.getSelf().setPseudo(this.vue.getDisplayedPseudo());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.commUDP.sendMessageModify();
|
this.commUDP.sendMessageInfoPseudo();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -99,7 +99,7 @@ public class ControleurStandard implements ActionListener, ListSelectionListener
|
||||||
try {
|
try {
|
||||||
Utilisateur.getSelf().setPseudo(this.vue.getDisplayedPseudo());
|
Utilisateur.getSelf().setPseudo(this.vue.getDisplayedPseudo());
|
||||||
this.commUDP.sendMessageConnecte();
|
this.commUDP.sendMessageConnecte();
|
||||||
this.commUDP.sendMessageAdd();
|
this.commUDP.sendMessageInfoPseudo();
|
||||||
|
|
||||||
this.vue.toggleEnableButtonConnexion();
|
this.vue.toggleEnableButtonConnexion();
|
||||||
this.vue.toggleEnableButtonDeconnexion();
|
this.vue.toggleEnableButtonDeconnexion();
|
||||||
|
|
|
@ -15,11 +15,11 @@ public class Utilisateur implements Serializable{
|
||||||
|
|
||||||
private static Utilisateur self;
|
private static Utilisateur self;
|
||||||
|
|
||||||
public Utilisateur(String id, String pseudo, String host) throws UnknownHostException {
|
public Utilisateur(String id, String pseudo, InetAddress ip) throws UnknownHostException {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.pseudo = pseudo;
|
this.pseudo = pseudo;
|
||||||
this.ip = InetAddress.getLocalHost();
|
this.ip = ip;
|
||||||
//System.out.println(InetAddress.getLocalHost());
|
System.out.println(InetAddress.getLocalHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,9 +41,8 @@ public class Utilisateur implements Serializable{
|
||||||
|
|
||||||
public static void setSelf(String id, String pseudo,String host) throws UnknownHostException {
|
public static void setSelf(String id, String pseudo,String host) throws UnknownHostException {
|
||||||
if(Utilisateur.self == null) {
|
if(Utilisateur.self == null) {
|
||||||
Utilisateur.self = new Utilisateur(id, pseudo, host);
|
Utilisateur.self = new Utilisateur(id, pseudo, InetAddress.getByName(host));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Utilisateur getSelf() {
|
public static Utilisateur getSelf() {
|
||||||
|
|
8
POO/src/messages/MauvaisTypeMessageException.java
Normal file
8
POO/src/messages/MauvaisTypeMessageException.java
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package messages;
|
||||||
|
|
||||||
|
public class MauvaisTypeMessageException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
69
POO/src/messages/Message.java
Normal file
69
POO/src/messages/Message.java
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
package messages;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import messages.Message.TypeMessage;
|
||||||
|
|
||||||
|
public abstract class Message implements Serializable {
|
||||||
|
|
||||||
|
public enum TypeMessage {JE_SUIS_CONNECTE, JE_SUIS_DECONNECTE, INFO_PSEUDO, TEXTE, IMAGE, FICHIER, MESSAGE_NUL}
|
||||||
|
protected TypeMessage type;
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static Instrumentation inst;
|
||||||
|
|
||||||
|
public TypeMessage getTypeMessage() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String attributsToString();
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.type+"###"+this.attributsToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Message stringToMessage(String messageString) {
|
||||||
|
try {
|
||||||
|
String[] parts = messageString.split("###");
|
||||||
|
switch (parts[0]) {
|
||||||
|
case "JE_SUIS_CONNECTE" :
|
||||||
|
return new MessageSysteme(TypeMessage.JE_SUIS_CONNECTE);
|
||||||
|
|
||||||
|
case "JE_SUIS_DECONNECTE" :
|
||||||
|
return new MessageSysteme(TypeMessage.JE_SUIS_DECONNECTE);
|
||||||
|
|
||||||
|
case "INFO_PSEUDO" :
|
||||||
|
return new MessageSysteme(TypeMessage.INFO_PSEUDO, parts[1], parts[2]);
|
||||||
|
|
||||||
|
case "TEXTE" :
|
||||||
|
return new MessageTexte(TypeMessage.TEXTE, parts[1]);
|
||||||
|
|
||||||
|
case "IMAGE" :
|
||||||
|
return new MessageFichier(TypeMessage.IMAGE, parts[1], parts[2]);
|
||||||
|
|
||||||
|
case "FICHIER" :
|
||||||
|
return new MessageFichier(TypeMessage.FICHIER, parts[1], parts[2]);
|
||||||
|
}
|
||||||
|
} catch (MauvaisTypeMessageException e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//tests ici
|
||||||
|
public static void main(String[] args) throws MauvaisTypeMessageException {
|
||||||
|
Message m1 = new MessageSysteme(TypeMessage.JE_SUIS_CONNECTE);
|
||||||
|
Message m2 = new MessageSysteme(TypeMessage.JE_SUIS_DECONNECTE);
|
||||||
|
Message m3 = new MessageSysteme(TypeMessage.INFO_PSEUDO, "pseudo156434518", "id236");
|
||||||
|
Message m4 = new MessageTexte(TypeMessage.TEXTE, "blablabla");
|
||||||
|
Message m5 = new MessageFichier(TypeMessage.FICHIER, "truc", ".pdf");
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(Message.stringToMessage(m1.toString()));
|
||||||
|
System.out.println(Message.stringToMessage(m2.toString()));
|
||||||
|
System.out.println(Message.stringToMessage(m3.toString()));
|
||||||
|
System.out.println(Message.stringToMessage(m4.toString()));
|
||||||
|
System.out.println(Message.stringToMessage(m5.toString()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
POO/src/messages/MessageFichier.java
Normal file
33
POO/src/messages/MessageFichier.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package messages;
|
||||||
|
|
||||||
|
import messages.Message.TypeMessage;
|
||||||
|
|
||||||
|
public class MessageFichier extends Message {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String contenu;
|
||||||
|
private String extension;
|
||||||
|
|
||||||
|
public MessageFichier(TypeMessage type, String contenu, String extension) throws MauvaisTypeMessageException{
|
||||||
|
if ((type==TypeMessage.IMAGE)||(type==TypeMessage.FICHIER)) {
|
||||||
|
this.type=type;
|
||||||
|
this.contenu=contenu;
|
||||||
|
this.extension=extension;
|
||||||
|
}
|
||||||
|
else throw new MauvaisTypeMessageException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContenu() {
|
||||||
|
return this.contenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExtension() {
|
||||||
|
return this.extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String attributsToString() {
|
||||||
|
return this.contenu+"###"+this.extension;
|
||||||
|
}
|
||||||
|
}
|
39
POO/src/messages/MessageSysteme.java
Normal file
39
POO/src/messages/MessageSysteme.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package messages;
|
||||||
|
|
||||||
|
public class MessageSysteme extends Message {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String pseudo;
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
public MessageSysteme(TypeMessage type) throws MauvaisTypeMessageException{
|
||||||
|
if ((type==TypeMessage.JE_SUIS_CONNECTE)||(type==TypeMessage.JE_SUIS_DECONNECTE)||(type==TypeMessage.MESSAGE_NUL)) {
|
||||||
|
this.type=type;
|
||||||
|
this.pseudo="";
|
||||||
|
this.id="";
|
||||||
|
}
|
||||||
|
else throw new MauvaisTypeMessageException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageSysteme(TypeMessage type, String pseudo, String id) throws MauvaisTypeMessageException {
|
||||||
|
if (type==TypeMessage.INFO_PSEUDO) {
|
||||||
|
this.type=type;
|
||||||
|
this.pseudo=pseudo;
|
||||||
|
this.id=id;
|
||||||
|
}
|
||||||
|
else throw new MauvaisTypeMessageException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPseudo() {
|
||||||
|
return this.pseudo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String attributsToString() {
|
||||||
|
return this.pseudo+"###"+this.id;
|
||||||
|
}
|
||||||
|
}
|
27
POO/src/messages/MessageTexte.java
Normal file
27
POO/src/messages/MessageTexte.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package messages;
|
||||||
|
|
||||||
|
import messages.Message.TypeMessage;
|
||||||
|
|
||||||
|
public class MessageTexte extends Message {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String contenu;
|
||||||
|
|
||||||
|
public MessageTexte(TypeMessage type, String contenu) throws MauvaisTypeMessageException{
|
||||||
|
if (type==TypeMessage.TEXTE) {
|
||||||
|
this.type=type;
|
||||||
|
this.contenu=contenu;
|
||||||
|
}
|
||||||
|
else throw new MauvaisTypeMessageException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContenu() {
|
||||||
|
return this.contenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String attributsToString() {
|
||||||
|
return this.contenu;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue