import java.net.*; import java.io.*; /* A pretty straightforward class, handles the client-side of the client/server connections. */ public class Client { Socket s; DataInputStream in; PrintStream out; /** * Do NOT use this one! */ public Client() throws IOException{ super(); } /** * Use this contructor! */ public Client(String host, int port) throws UnknownHostException , IOException { s = new Socket(host,port); in = new DataInputStream(s.getInputStream()); out = new PrintStream(s.getOutputStream()); // send("...this is the clientConstructor, echo this please...\r"); System.out.println("...client..."); } public void send(String msg) { System.out.println("...send..."); out.println(msg); } public void close() throws IOException { System.out.println("Closing connection...\r"); in.close(); out.close(); s.close(); } public void show() throws IOException { // read/print all input so far String str; boolean done = false; System.out.println("...showing..."); while (!done) { str = in.readLine(); if (str != null) System.out.println("--->"+str); if (str == null || in.available() == 0) done = true; } } }