Modification du processus TCP
This commit is contained in:
parent
ba901972cd
commit
19ca764685
5 changed files with 106 additions and 30 deletions
|
@ -44,4 +44,16 @@ public class Historique {
|
||||||
public Utilisateur getUser2() {
|
public Utilisateur getUser2() {
|
||||||
return User2;
|
return User2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void afficher10derniers() {
|
||||||
|
int n =10;
|
||||||
|
if(HistoriqueHorodate.size()<=10) {
|
||||||
|
n = HistoriqueHorodate.size();
|
||||||
|
}
|
||||||
|
for(int i = 0; i<n;i++) {
|
||||||
|
String exp = HistoriqueHorodate.get(i).getSource().toString();
|
||||||
|
String payload = HistoriqueHorodate.get(i).getMessage();
|
||||||
|
System.out.println(exp+" : "+payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ public class MessageHorodate {
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public MessageHorodate(Utilisateur destinataire, Utilisateur source, String Message, int type) {
|
public MessageHorodate(Utilisateur destinataire, Utilisateur source, String Message, int type) {
|
||||||
this.destinataire = destinataire ;
|
this.setDestinataire(destinataire) ;
|
||||||
this.source = source ;
|
this.setSource(source) ;
|
||||||
this.Message = Message ;
|
this.setMessage(Message) ;
|
||||||
this.dateHorodatage = new Date();
|
this.dateHorodatage = new Date();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,11 @@ public class MessageHorodate {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String Msg = "";
|
String Msg = "";
|
||||||
Msg += ("Destinataire:" + this.destinataire + "\n") ;
|
Msg += ("Destinataire:" + this.getDestinataire() + "\n") ;
|
||||||
Msg += ("Source:" + this.source+ "\n") ;
|
Msg += ("Source:" + this.getSource()+ "\n") ;
|
||||||
Msg += ("Type:"+ this.type+ "\n");
|
Msg += ("Type:"+ this.type+ "\n");
|
||||||
Msg += ("Date:" + this.dateToString() + "\n") ;
|
Msg += ("Date:" + this.dateToString() + "\n") ;
|
||||||
Msg += ("Message:" + this.Message + "\n" );
|
Msg += ("Message:" + this.getMessage() + "\n" );
|
||||||
return Msg ;
|
return Msg ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,4 +94,36 @@ public class MessageHorodate {
|
||||||
return mh ;
|
return mh ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Utilisateur getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSource(Utilisateur source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Utilisateur getDestinataire() {
|
||||||
|
return destinataire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestinataire(Utilisateur destinataire) {
|
||||||
|
this.destinataire = destinataire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int Type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,10 +95,21 @@ class RunnerTCPEnvoi implements Runnable {
|
||||||
String msg;
|
String msg;
|
||||||
while(true){
|
while(true){
|
||||||
msg = sc.nextLine();
|
msg = sc.nextLine();
|
||||||
|
if(msg.equals("--STOP--")) {
|
||||||
|
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),msg,0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),msg,1);
|
MessageHorodate mh = new MessageHorodate(Destinataire,app.getMe(),msg,1);
|
||||||
out.println(msg);
|
out.println(mh);
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
System.out.println("Fermeture du thread d'envoi");
|
||||||
|
in.close();
|
||||||
|
link.close();
|
||||||
|
}catch(Exception e) {
|
||||||
|
// Gestion de l'exception de la fermeture de la socket
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,30 +131,51 @@ class RunnerTCPEcoute implements Runnable {
|
||||||
//InputStream is = link.getInputStream();
|
//InputStream is = link.getInputStream();
|
||||||
BufferedReader in = new BufferedReader (new InputStreamReader (link.getInputStream()));
|
BufferedReader in = new BufferedReader (new InputStreamReader (link.getInputStream()));
|
||||||
|
|
||||||
String line = in.readLine();
|
String line = "";
|
||||||
|
String dest = "";
|
||||||
|
String src = "";
|
||||||
|
String type = "";
|
||||||
|
String date = "";
|
||||||
|
String payload = "";
|
||||||
String msg = "";
|
String msg = "";
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
|
line = in.readLine();
|
||||||
//if(!msg.equals("")) {
|
if(line.split(":")[0].equals("Destinataire")) {
|
||||||
System.out.println("Received: "+ line);
|
if(msg.equals("")) {
|
||||||
line = in.readLine();
|
dest = line+"\n";
|
||||||
//}
|
}
|
||||||
/*if((line.split(" ")[0].equals("Destinataire"))) {
|
else {
|
||||||
if(msg != "") {
|
msg=dest+src+type+date+payload;
|
||||||
MessageHorodate mh = MessageHorodate.stringToMessageHorodate(msg);
|
payload = "";
|
||||||
// on ajoute le msg à son historique
|
MessageHorodate mh = MessageHorodate.stringToMessageHorodate(msg);
|
||||||
Historique h = app.getHist(mh.);
|
if(mh.getType()==1) {
|
||||||
|
Historique h = app.getHist(mh.getSource().getPseudo());
|
||||||
h.addMessage(mh);
|
h.addMessage(mh);
|
||||||
// on update la liste des historiques de app
|
app.majHistorique(mh.getSource().getPseudo(), h);
|
||||||
app.majHistorique(User2.getPseudo(), h);
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
// On recree un messagehorodate à partir du message reçu
|
|
||||||
|
|
||||||
// on ajoute le msg à son historique
|
}
|
||||||
|
}
|
||||||
|
else if(line.split(":")[0].equals("Source")) {
|
||||||
|
src = line+"\n";
|
||||||
|
}
|
||||||
|
else if(line.split(":")[0].equals("Type")) {
|
||||||
|
type = line+"\n";
|
||||||
|
}
|
||||||
|
else if(line.split(":")[0].equals("Date")) {
|
||||||
|
date = line+"\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
payload += line+"\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Received: "+ line);
|
||||||
|
|
||||||
|
|
||||||
// on update la liste des historiques de app
|
|
||||||
|
|
||||||
}
|
}
|
||||||
System.out.println("Finishing thread");
|
System.out.println("Finishing thread");
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class UDPEchange {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SocketException e) {
|
} catch (Exception e) {
|
||||||
System.out.println("unable to get current IP " + e.getMessage());
|
System.out.println("unable to get current IP " + e.getMessage());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class Utilisateur extends Object {
|
||||||
id=mots[10];
|
id=mots[10];
|
||||||
Utilisateur user = null;
|
Utilisateur user = null;
|
||||||
try {
|
try {
|
||||||
user = new Utilisateur(name,port,InetAddress.getByName(ip.split("/")[0]));
|
user = new Utilisateur(name,port,InetAddress.getByName(ip.split("/")[1]));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue