I'm beginner in Java programming and I have to realize a project with sockets. I'm trying to get the data from the client to connect, but I'm stuck in reading the data from the DAtaInputStream. I don't know why the run method stops executing in the line "op=din.readInt()".
public class ServerWorker extends Thread {
public final Socket clientSocket;
Server s;
BDClass con;
boolean stillConnecting = true;
Thread runner;
public ServerWorker(Server s, Socket clientSocket) throws ClassNotFoundException {
this.con = new BDClass();
this.clientSocket = clientSocket;
this.s = s;
this.runner = new Thread(this);
this.runner.start();
}
public boolean login(String nom, String pass) throws SQLException, IOException {
ResultSet User;
if (nom != "" && pass != "") {
if (con.Authentifier(nom, pass)) {
User = con.TrouverUtilisateur(nom);
new ProfilFenetre(con.getFriends(User.getInt(1)), User).setVisible(true);
return true;
} else {
return false;
}
} else {
return false;
}
}
@Override
public void run() {
DataInputStream din;
DataOutputStream dout;
int op = 0;
ConnexionFenetre f;
try {
f = new ConnexionFenetre(s, clientSocket);
f.setVisible(true);
System.out.print("viide");
while (true) {
try {
if (true) {
din = new DataInputStream(clientSocket.getInputStream());
dout = new DataOutputStream(clientSocket.getOutputStream());
op = din.readInt();
System.out.print(op);
switch (op) {
case 0: {
System.out.println("no request");
break;
}
case 1: {
DataInputStream din1 = new DataInputStream(clientSocket.getInputStream());
DataInputStream din2 = new DataInputStream(clientSocket.getInputStream());
System.out.print(din1.readUTF() + " llll " + din2.readUTF());
if (this.login(din1.readUTF(), din2.readUTF())) {
f.dispose();
dout.writeUTF("you are connected!!");
} else {
dout.writeUTF("mot de passe ou username faux!!");
}
break;
}
default: {
}
}
}
} catch (IOException e) {
System.err.print(e.getMessage());
} catch (SQLException ex) {
System.err.print(ex.getMessage());
Logger.getLogger(ServerWorker.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (IOException ex) {
Logger.getLogger(ServerWorker.class.getName()).log(Level.SEVERE, null, ex);
System.err.print(ex.getMessage());
}
}
}