package sockets2LaPelicula;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import sockets2LaPelicula.Cliente2;
import sockets2LaPelicula.Servidor2;
public class Cliente2 {
public void ejecutar() {
try {
System.out.print("Lanzando conexión....");
Socket socket = new Socket ("127.0.0.1", Servidor2.PUERTO);//Conectamos al servidor
System.out.println("[OK]");
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));//Bufer de lectura
PrintWriter pw = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));//Buffer de escritura
String cadenaRecibida = br.readLine();
System.out.println(cadenaRecibida);
pw.println("cadena recibida" + cadenaRecibida);
pw.flush();
System.out.println("Fin del Cliente");
}catch(IOException e){
e.printStackTrace();
}
}
public void ejecutarInfinito() {
try {
System.out.print("Lanzando conexión....");
Socket socket = new Socket ("127.0.0.1", Servidor2.PUERTO);//Conectamos al servidor
System.out.println("[OK]");
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));//Bufer de lectura
PrintWriter pw = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));//Buffer de escritura
String lineaLeida ="";
Scanner teclado = new Scanner(System.in);
while(true) {
lineaLeida = teclado.nextLine();
pw.println(lineaLeida);
pw.flush();
}
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
Cliente2 client = new Cliente2();
client.ejecutarInfinito();
}
}