Skip to content

Instantly share code, notes, and snippets.

@urieljuliatti
Created March 15, 2012 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urieljuliatti/2040567 to your computer and use it in GitHub Desktop.
Save urieljuliatti/2040567 to your computer and use it in GitHub Desktop.
modelo3.java
// Sistemas distribuidos
Servidor.main{
ServerSocket servidor = new ServerSocket(int porta);
ArrayList<Socket> clientes = new ArrayList<Socket>(); // Só cria para a conexão
while(true){
Socket cliente = servidor.accept();
clientes.add(cliente);
Observador observador = new Observador(cliente, clientes); // runnable
Thread processo = new Thread(observador);
processo.start();
}
}
public class Observador implements Runnable{
private Socket cliente = null;
private ArrayList<Socket> clientes = null;
public Observador(Socket cliente, ArrayList<Socket> clientes)
{
this.cliente = cliente;
this.clientes = clientes;
}
public void run()
{
Scanner entrada = new Scanner(cliente.getInputStream());
while(entrada.hasNextLine())
{
String msn = entrada.nextline();
for(int i = 0; i < clientes.size(); i++)
{
Socket atual = clientes.get(i);
PrintStream saida = new PrintStream(atual.getOutputStream());
saida.println(saida);
}
}
}
}
@urieljuliatti
Copy link
Author

Só tem troll! hahaha. Então, hlmerscher, é sim! É do Wesley :)

@cccaldas
Copy link

cccaldas commented Jan 3, 2013 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment