// tcpClient.java // uso : java tcpClient // asume puerto 1500 import java.net.*; import java.io.*; public class tcpClient { public static void main(String[] args) { int port = 1500; String server = "localhost"; Socket socket = null; String lineToBeSent; BufferedReader input; PrintWriter output; int ERROR = 1; if(args.length == 2) { server = args[0]; try { port = Integer.parseInt(args[1]); } catch (Exception e) { System.out.println("Puerto = 1500"); port = 1500; } } try { socket = new Socket(server, port); System.out.println("Conectado con servidor " + socket.getInetAddress() + ":" + socket.getPort()); } catch (UnknownHostException e) { System.out.println(e); System.exit(ERROR); } catch (IOException e) { System.out.println(e); System.exit(ERROR); } try { input = new BufferedReader(new InputStreamReader(System.in)); output = new PrintWriter(socket.getOutputStream(),true); // lee entrada y transmite al servidor while(true) { lineToBeSent = input.readLine(); // detiene si la entrada es "." if(lineToBeSent.equals(".")) break; output.println(lineToBeSent); } } catch (IOException e) { System.out.println(e); } try { socket.close(); } catch (IOException e) { System.out.println(e); } } }