package jelouda; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner; public class Cliente { public void ejecutar() { try { System.out.print("Lanzando conexión...."); Socket socket = new Socket ("127.0.0.1", Servidor.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", Servidor.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) { Cliente client = new Cliente(); client.ejecutarInfinito(); } }