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);
}
}
}
}
@m3nd3s
Copy link

m3nd3s commented Mar 15, 2012

@urieljuliatti
Copy link
Author

Troll! Eu faço um gist de rascunho da aula e você me trolla hauahuahuahuauh

@m3nd3s
Copy link

m3nd3s commented Mar 15, 2012

Fala sério, nunca mais você vai esquecer dessa aula :-)

@bitmaybewise
Copy link

Hum... deixa adivinhar, aula do Wesley. :-)

O chat que fiz como trabalho dele está no github, se quiser ver é só acessar: https://github.com/hlmerscher/jchat
Só não repara no MVC que tentei fazer, porque na época não entendia direito.

@cccaldas
Copy link

eh dotineti ???

@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