Compare commits

..

No commits in common. "50af9cb4b6c166c86926bb6e9650427d35dc0cc2" and "658dd49aeaab6eeab4f1b5a9dfd73e27856ff157" have entirely different histories.

6 changed files with 43 additions and 83 deletions

View file

@ -1,4 +1,2 @@
/UserListeningThreadTCP.class
/UserListeningThreadUDP.class
/UserConnexionthreadTCP.class
/Database.class

View file

@ -1,9 +0,0 @@
public class Database {
private User myUser;
public void Database() {
}
}

View file

@ -194,7 +194,6 @@ public class User{
e.printStackTrace();
}
String input;
System.out.println(this.getPseudo()+" reçoit un message");
try {
while (!(input=in.readLine()).equals("end")) {
System.out.print("client_recoit:"+input);
@ -424,9 +423,9 @@ public class User{
public static void main(String[] args) throws IOException, InterruptedException {
// Création des utilisateurs
User usr2 = new User(12226,portUDPlistening_remoteUsr2,22222,"Mike"); // simulation d'un utilisateur distant n1
User usr3 = new User(12224,portUDPlistening_remoteUsr3,22223,"Alice"); // simulation d'un utilisateur distant n2
User usr1 = new User(12225,20001,22221); // Notre utilisateur local
User usr2 = new User(12222,portUDPlistening_remoteUsr2,22222,"Mike"); // simulation d'un utilisateur distant n1
User usr3 = new User(12223,portUDPlistening_remoteUsr3,22223,"Alice"); // simulation d'un utilisateur distant n2
User usr1 = new User(12221,20001,22221); // Notre utilisateur local
// Fonction appelé par notre utilisateur local
usr1.getOneActiveUser();

View file

@ -1,55 +0,0 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.DatagramSocket;
import java.net.Socket;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class UserConnexionthreadTCP extends Thread{
private User myUser;
private Socket socket;
public UserConnexionthreadTCP(String s,User user,Socket socket) {
super(s);
this.myUser = user;
this.socket=socket;
}
public void run() {
Socket link = this.socket;
try {
BufferedReader in =new BufferedReader(new InputStreamReader(link.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PrintWriter out=null;
try {
out = new PrintWriter(link.getOutputStream(),true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(myUser.getPseudo()+" envoie un message");
out.println(dateFormat.format(date));
out.println("end");
String input;
/*while (!(input=in.readLine()).equals("end")) {
System.out.print("server_recoit:"+input);
}*/
try {
link.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View file

@ -15,7 +15,7 @@ import java.util.Date;
public class UserListeningThreadTCP extends Thread{
private User myUser;
//private DatagramSocket dgramSocket=null;
private DatagramSocket dgramSocket=null;
/* CONSTRUCTOR OF UserListeningThreadTCP
* $parametres
@ -27,20 +27,13 @@ public class UserListeningThreadTCP extends Thread{
public UserListeningThreadTCP(String s,User user) {
super(s);
this.myUser = user;
/* try {
try {
this.dgramSocket = new DatagramSocket(this.myUser.getPortTCP(),this.myUser.getAddIP());
} catch (IOException e) {
e.printStackTrace();
}
*/
}
public void accept(ServerSocket servSocket) throws IOException {
UserConnexionthreadTCP threadtcp= new UserConnexionthreadTCP("Chat_with_"+myUser.getPseudo(),myUser,servSocket.accept());
threadtcp.start();
}
@ -62,14 +55,48 @@ public class UserListeningThreadTCP extends Thread{
// TODO Auto-generated catch block
e.printStackTrace();
}
Socket link=null;
try {
this.accept(servSocket);
link = servSocket.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
BufferedReader in =new BufferedReader(new InputStreamReader(link.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PrintWriter out=null;
try {
out = new PrintWriter(link.getOutputStream(),true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.println("awaiting data...");
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
out.println(dateFormat.format(date));
out.println("end");
String input;
/*while (!(input=in.readLine()).equals("end")) {
System.out.print("server_recoit:"+input);
}*/
try {
link.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
servSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -81,7 +108,7 @@ public class UserListeningThreadTCP extends Thread{
* interrupt UDP listening threadS
*/
public void close() {
// this.dgramSocket.close();
this.dgramSocket.close();
System.out.println("End of listing thread TCP ("+this.myUser.getPseudo()+")");
try {
this.interrupt();