Boa noite pessoal gostaria que fazer um chat bem simples, aonde o server deve conter thread para multiplas conexões. Eu até fiz um server e o cliente, so que não sei como colocar thread no meu server. Alguém poderia me ajudar ? Segue o código do server e do cliente abaixo. Obrigado !
[size=18]Servidor[/size]
import java.io.*;
import java.net.*;
import java.util.*;
public class Servidor {
public static void main(String[] args) throws IOException {
ServerSocket servidor = new ServerSocket(5000);
System.out.println("Porta 5000 aberta!");
Scanner s = new Scanner(cliente.getInputStream());
while (s.hasNextLine()) {
System.out.println(s.nextLine());
}
s.close();
servidor.close();
cliente.close();
}
}
[size=18]Cliente[/size]
import java.io.*;
import java.net.*;
import java.util.*;
public class Cliente {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket cliente = new Socket("127.0.0.1", 5000);
System.out.println("O cliente se conectou ao servidor!");
Scanner teclado = new Scanner(System.in);
PrintStream saida = new PrintStream(cliente.getOutputStream());
while (teclado.hasNextLine()) {
saida.println(teclado.nextLine());
}
saida.close();
teclado.close();
cliente.close();
}
}