Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package teste;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.util.Scanner;
- public class Client implements Runnable {
- private Socket cliente;
- public Client(Socket cliente) {
- this.cliente = cliente;
- }
- public static void main(String args[]) throws UnknownHostException, IOException {
- Socket socket = new Socket("127.0.0.1", 12345);
- Client c = new Client(socket);
- Thread t = new Thread(c);
- t.start();
- }
- public void run() {
- try {
- PrintStream saida;
- System.out.println("O cliente conectou ao servidor");
- Scanner teclado = new Scanner(System.in);
- saida = new PrintStream(this.cliente.getOutputStream());
- while (teclado.hasNextLine()) {
- String input = teclado.nextLine();
- saida.println(input);
- if (input.equals(" ")) {
- break;
- }
- }
- saida.close();
- teclado.close();
- this.cliente.close();
- System.out.println("Fim do cliente!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment