bonjour,
je développe une application en réseau en utilisant les sockets au 1er lieu l'application marche à la perfective mais lors de l'ajout de l'authentificaton du serveur ça m'a fait des problèmes par exemple (l'envoi de la liste des gens connecté a chaque connexion d'un autre)
c'est la partie de l'authentification du serveur
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| //connexion a la bdd
cbd = new ConnexionBD();
cbd.connexion();
//**************//
user = text_Nom_utilisateur.getText();
password=text_Mot_de_passe.getText();
try {
t = cbd.rechercheProf(user, password);
} catch (SQLException ex) {
System.out.println(ex);
}
if (t) {
dispose();
tau= new treadAuth();
tau.start();
}
else {
JFrame j = new JFrame();
JOptionPane.showMessageDialog(j, "le nom d'utilisateur ou le mot de passe est incorrect");
dispose(
FauthentificationEnseignant fe = new FauthentificationEnseignant();
fe.setVisible(true);
} |
1 2 3 4 5 6 7 8 9 10
| public class treadAuth extends Thread {
public void run(){
GClient gc=new GClient();
gc.connexion();
}
} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| void connexion() {
try {
//la connexion du serveur
ServerSocket sersoc = new ServerSocket(2012);
System.out.println("@ DE SOCKET "+sersoc);
clients = new Vector();
System.out.println("waitting for clients...");
f.setVisible(true);
while (true) {
//nouveau client vient de se connecter
soc = sersoc.accept();
entree = new ObjectInputStream(soc.getInputStream());
//**************//
out=soc.getOutputStream();
sortie = new ObjectOutputStream(soc.getOutputStream());
//l'ajout du nouveau client dans la liste des sortie ses client connecter
clientO.add(out);
client.add(sortie);
System.out.println("Client connecter de "+soc.getLocalAddress().getHostName());
f.gc=this;
treadS ts=new treadS();
ts.in=entree;
ts.fs=f;
ts.start();
}
} catch (IOException ex) {
Logger.getLogger(GClient.class.getName()).log(Level.SEVERE, null, ex);
} |
le serveur s'execute normal
le coté du client : (authentification)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| try {
soc = new Socket("127.0.0.1", 2012);// demand de cnxion
sortie = new ObjectOutputStream(soc.getOutputStream());
entree = new ObjectInputStream(soc.getInputStream());
// br=new InputStreamReader(soc.getInputStream());
//LA CONNEXION 0 LA BASE DE DONNEE
cbd = new ConnexionBD();
cbd.connexion();
//**************//
user = text_Nom_utilisateur.getText();
password = text_Mot_de_passe.getText();
try {
t = cbd.rechercheEtudiant(user, password);
} catch (SQLException ex) {
Logger.getLogger(FauthentificationEtudiant.class.getName()).log(Level.SEVERE, null, ex);
}
if (t) {
NewJFrameC fc = new NewJFrameC();
fc.fa = this;
fc.setTitle(user);
Date d=new Date();
String date=fc.getDate(d);
cbd.insertUser(user, date);
fc.des.setText(" ღ ღ ღ ღ ღ WELCOME ღ ღ ღ ღ ღ " + user + " ღ ღ ღ ღ ღ ");
fc.setVisible(true);
try {
User u = new User();
u.user = user;
sortie.writeObject(u);
sortie.reset();
} catch (Exception ex) {
ex.printStackTrace();
}
this.dispose();
fc.in = entree;
fc.out = sortie;
fc.outs = soc.getOutputStream();
treadC tc = new treadC();
tc.in = entree;
tc.fa = this;
tc.fc = fc;
tc.start();
} else {
JFrame j = new JFrame();
JOptionPane.showMessageDialog(j, "le nom d'utilisateur ou le mot de passe est incorrect");
dispose();
FauthentificationEtudiant fa = new FauthentificationEtudiant();
fa.setVisible(true);
}
// TODO add your handling code here:
} catch (IOException e) {
e.printStackTrace();
} |
les erreurs apparu lors de connexion du 2 clients
coté client:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: javax.swing.plaf.synth.SynthTableHeaderUI
coté serveur:
java.io.NotSerializableException: javax.swing.plaf.synth.SynthTableHeaderUI
Partager