/** * Fail DirKlient.java * @author Jaanus Poial * @version 0.1 kevad 99 */ import java.net.*; import java.io.*; public class DirKlient { public static void main(String[] parameetrid) { String serveriNimi = "localhost"; // server int pordinumber = 7654; // TCP-port if (parameetrid.length == 1) pordinumber = Integer.parseInt (parameetrid [0]); else if (parameetrid.length > 1) { serveriNimi = parameetrid [0]; pordinumber = Integer.parseInt (parameetrid [1]); } try { Socket pistik = new Socket (serveriNimi, pordinumber); InputStream sisse = pistik.getInputStream(); BufferedReader svoog = new BufferedReader (new InputStreamReader (sisse)); OutputStream valja = pistik.getOutputStream(); PrintWriter vvoog = new PrintWriter (new OutputStreamWriter (valja), true); BufferedReader klav = new BufferedReader (new InputStreamReader (System.in)); System.out.print ("Anna tellimus: "); String tellimus = klav.readLine(); System.out.println ("Saadan tellimuse: host = " + pistik.getInetAddress() + " , port = " + pistik.getPort() + "\n localhost = " + pistik.getLocalAddress() + " , localport = " + pistik.getLocalPort()); vvoog.println (tellimus); System.out.println ("Sain vastuseks:"); String rida; while ((rida = svoog.readLine()) != null) System.out.println (rida); pistik.close(); } catch (IOException e) { System.out.println ("S/V viga: " + e); } } // main lopp } // DirKlient lopp