Client/Server com multi-clients com socket

0 respostas
J

fala pessoal,

sou novo no java e aqui no forum tb, to fazendo um projetinho em java que envolve cliente servidor, o cliente conecta e solicita alguma coisa so serve, parar um cliente ta funcionando, agora como eu trato multi-clientes?

vejam o código do server:

import java.net.*; 
import java.io.*;

public class DicServer {
   public static void main(String[] args) throws IOException {
      ServerSocket ServidorSocket = null;
      Socket ClientSocket = null;
      try{
         try {
            ServidorSocket = new ServerSocket(6962);
         } catch (IOException e) {
            System.err.println("Erro ao acessar a porta 6969");
            System.exit(1);
         }
         try {
            ClientSocket = ServidorSocket.accept();
         } catch (IOException e) {
            System.err.println("Erro ao aceitar a conexao");
            System.exit(1);
         }
         PrintWriter out = new PrintWriter(ClientSocket.getOutputStream(), true);
         BufferedReader in = new BufferedReader(new InputStreamReader(ClientSocket.getInputStream()));
         String inputLine, outputLine;
         while (true)
         {
           inputLine = in.readLine();            
            System.out.println("Cliente Solicitou a Palavra: " + inputLine);
          .........................................

        out.close();
        in.close();
      }
      finally
      {
         ClientSocket.close();
         ServidorSocket.close();
      }
   }
}
Criado 30 de maio de 2007
Respostas 0
Participantes 1