// MODULO CLIENTE EN EL USO DE SOCKETS import java.lang.System; import java.net.Socket; import java.net.InetAddress; import java.net.UnknownHostException; import java.io.*; public class Cliente_2 { public static void main(String args[]) throws IOException { CHAT portTalk = new CHAT(args); portTalk.chat(); } } class CHAT { Socket ConecciOn; DataOutputStream outStream; BufferedReader inStream; public CHAT(String args[]) throws IOException { if(args.length!=2) { System.out.println("Uso: java Cliente host port"); System.exit(1); } String Destino = args[0]; ConecciOn = new Socket(Destino, Integer.valueOf(args[1]).intValue()); inStream = new BufferedReader(new InputStreamReader(ConecciOn.getInputStream())); outStream = new DataOutputStream(ConecciOn.getOutputStream()); System.out.println("Conectado a "+Destino); } public void chat() throws IOException { boolean fin = false; String outLinea, inLinea; while (!(outLinea = Contesta()).equalsIgnoreCase("Salir")) { outStream.writeBytes(outLinea); outStream.write(10); outStream.flush(); System.out.print("<< "); inLinea = inStream.readLine(); System.out.println(inLinea); System.out.flush(); } ConecciOn.close(); } String Contesta() throws IOException { BufferedReader Teclado = new BufferedReader(new InputStreamReader(System.in)); System.out.print(">> "); System.out.flush(); return Teclado.readLine(); } }