Problema com Socket em Threads Concorrentes para envio de arquivo

0 respostas
agranado2k

Oi galera,

Estou tendo um problema em uma implementacão minha. Ela seria uma espécie de servidor de arquivos, onde os clientes, no meu caso browsers, pedem um arquivo. Quanto ao fato de cliente pedir e receber o arquivo, tudo bem. Meu problema é que não está funcioando de modo concorrente. O segundo cliente tem que esperar o primeiro cliente, e assim por diante. Mas gostaria de fazer que todos pegassem em concorrência. Eu inicio uma thread para cada cliente, mas por algum motivo elas estão se bloqueando, ou seria problema do socket?
Meu código está abaixo.

m_ServerSocket = new ServerSocket(listenPort);            
  log.info("Listening for clients on " + listenPort + "...");
  
 while(true) {
    		try {
    			Client newClient = new Client();
        		log.debug("Waiting for clients...");
                         newClient.setHttpSocket( m_ServerSocket.accept() );
                                
			new Thread( new GetFile( newClient ) ).start();
                }
               catch(IOException ioe) {
                        log.error("Exception encountered on accept. Ignoring. Stack Trace :");
                         ioe.printStackTrace();
            }
            catch (ClientAcceptException e) {
			log.error(e.getMessage());
	    }
        
public class GetFile {
          .....
        public GetFile (Client client) {
                        this.m_client = client;
                        this.httpSocket = client.getSocket();
                try {			
			this.input = this.httpSocket.getInputStream();
			this.output = this.httpSocket.getOutputStream();
		} catch (IOException e) {			
			throw new ClientAcceptException(e.getMessage());			
		}
				
		this.inputReader = new InputStreamReader(this.input);
		this.bufReader = new BufferedReader(this.inputReader);
		this.ipAddress = this.httpSocket.getInetAddress();			

        }
       
       public byte[] getData() {
                   .......
         }
        public void run() {
                this.m_client.getOutput().write( getData() );
        }

}

Galera, ajudem-me!!!! :)

Abracos!!!!

Criado 25 de agosto de 2008
Respostas 0
Participantes 1