Multi-Threaded TCP Game Server Implementation
Classified in Computers
Written at on English with a size of 1.34 KB.
Clientes ligam-se a servidor por TCP para jogarem. Pode ter entre 20 a 30 jogadores, de preferência 30, mas se jogador esperar mais de 1 minuto a partida começa com pelo menos 20. O jogador envia o nome ao servidor e fica à espera que o jogo comece e nessa altura é informado dos nomes dos outros.
1. Apresentar uma classe que implementa a interface em que os métodos têm que ser invocados em multi-thread.
Interface Jogo { List inscrever(String nome);}
public class Cliente {
public Cliente(Socket s) throws Exception {
PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
BufferedReader bf = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedReader terminal = new BufferedReader(new InputStreamReader(System.in));
Thread x = new Thread() {
public void run() {
try { String x; while ((x = terminal.readLine()) != null) { pw.println(x); }}
catch (Exception e) {}}}; s.start();
Thread y = new Thread() { public void run() {
try { String x; while ((x = bf.readLine()) != null) { System.out.println(x); }
catch (Exception e) {}}}; y.start(); }
public static void main(String[] args) {
try { Socket c = new Socket(