I have an application that is based on server- multiple clients interaction.This is the thread that i use in the server class to create a new thread where i accept all the new sockets:
Thread acceptingThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Socket s = serverSocket.accept();
listaSocket.add(s);
listaOis.add(new ObjectInputStream(s.getInputStream()));
listaOos.add(new ObjectOutputStream(s.getOutputStream()));
System.out.println("Client connected");
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
acceptingThread.start();
private ServerSocket serverSocket;
private ArrayList<Socket> listaSocket;
private ArrayList<ObjectInputStream> listaOis;
private ArrayList<ObjectOutputStream> listaOos;
The lines that block the programs are :
listaOis.add(new ObjectInputStream(s.getInputStream()));
listaOos.add(new ObjectOutputStream(s.getOutputStream()));