Está en la página 1de 2

import java.io.

IOException;
import java.net.*;
import java.io.*;
public class ClienteEcho {
String host = "localhost";
int puerto = 8;
public ClienteEcho() {
try {

// --- creando el socket

Socket s = new Socket(host,puerto);

// --- Obteniendo el flujo de entrada

BufferedReader entrada=

new BufferedReader(new
InputStreamReader(s.getInputStream()));

// --- Obteniendo el flujo de salida

PrintWriter salida=new PrintWriter( s.getOutputStream(),true);

salida.println("Hola, esta es una prueba");


System.out.println(entrada.readLine());

// -- cerramos el socket

s.close();
} catch (UnknownHostException e) {

// TODO Auto-generated catch block


e.printStackTrace();
} catch (IOException e) {

// No existe un servidor en este puerto

e.printStackTrace();
}

public static void main(String[] args) {

ClienteEcho ce= new ClienteEcho();

También podría gustarte