/** Document the purpose of this class. * * @version 1.0 * @author CDK segunda edición */ import java.net.*; import java.io.*; public class ClienteTCP { public static void main(String[] args) { // los argumentos proporcionan el mensaje y el nombre del host destino try { int puertoServicio = 7896; //Socket s = new Socket(args[1], puertoServicio); Socket s = new Socket("nombre.de.host", puertoServicio); DataInputStream entrada = new DataInputStream(s.getInputStream()); DataOutputStream salida = new DataOutputStream(s.getOutputStream()); salida.writeUTF("Este es un mensaje"); // UTF es una codificación de Strings S4.3 String datos = entrada.readUTF(); System.out.println("Recibido: " + datos); s.close(); } catch (UnknownHostException e) { System.out.println("Socket: " + e.getMessage()); } catch (EOFException e) { System.out.println("EOF: " + e.getMessage()); } catch (IOException e) { System.out.println("IO: " + e.getMessage()); } } }