I am currently developing a client-server application and I have this problem: I want to create a different class instance depending on what the connected socket sends, but it only creates the first instance then it stucks. Here is some piece of code:
Socket clientSocket = null;
ServerSocket server = null;
String buff = null;
transfer tr = null;
colectieClienti clienti = new colectieClienti();
And:
while (true) {
try {
clientSocket = server.accept();
buff = (new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))).readLine();
if (buff.equals("client")) {
(colectieClienti.useri[colectieClienti.nrUseri++] = new clientThread(clientSocket, stmt)).start();
} else {
tr = new transfer(clientSocket);
tr.start();
}
} catch (IOException ex) {
System.out.println(ex);
}
}
I have to mention that clientThread is a class that extends Thread and communicates with a GUI, and transfer is a class that only send some files from client to server. The logic is something like this: In the GUI the user connects to the server, so it is created a new instance of clientThread and after this, when the user press a button it creates a new socket (on the client side and send a message to the server, something like "I want to create a new instance of transfer class, which is done by the buff) and receive the data. But it only creates the clientThread instance and then it stucks. Can anyone help me?
LE: This is the constructor of clientThread
public clientThread(Socket socket, Statement statement) {
comunicare = socket;
try {
oStream = comunicare.getOutputStream();
is = new BufferedReader(new InputStreamReader(comunicare.getInputStream()));
os = new PrintStream(oStream);
} catch (IOException ex) {
System.out.println(ex);
}
this.statement = statement;
}