All pastes #330952 Raw Edit

Miscellany

public java v1 · immutable
#330952 ·published 2007-01-28 12:38 UTC
rendered paste body
import java.io.*;import java.net.*;public class KnockKnockClient {    public static void main(String[] args) throws IOException {                Socket kkSocket = null;        PrintWriter out = null;        //BufferedReader in = null;                try {                        // open socket            kkSocket = new Socket(args[0], 4444);                        //establish stream            out = new PrintWriter(kkSocket.getOutputStream(), true);                                } catch (UnknownHostException e) {            System.err.println("Don't know about host: localhost.");            System.exit(1);        } catch (IOException e) {            System.err.println("Couldn't get I/O for the connection to: " + args[0]);            System.exit(1);        }                                // ------------------------------------------        try {            // Open the file that is the first            // command line parameter            FileInputStream fstream = new FileInputStream(args[1]);                        // Convert our input stream to a            // DataInputStream            DataInputStream fromUser = new DataInputStream(fstream);                        // Continue to read lines while            // there are still some left to read                                    int byte_;            while ((byte_ = fstream.read()) != -1)                out.write(byte_);                        fromUser.close();        } catch (Exception e) {            System.err.println("File input error");        }                // ------------------------------------------                                        System.out.println("Closing connection.");        out.close();                kkSocket.close();    }}