
// simpletalk CLIENT in java

import java.lang.*;     //pld
import java.net.*;      //pld
import java.io.*;
//import java.io.Externalizable;

public class stalkc {
	public stalkc () {}
    static public BufferedReader bin;
    static public int destport = 5432;

    //============================================================

    static public void main(String args[]) {
		bin = new BufferedReader(new InputStreamReader(System.in));
	    String desthost = args[0]; //"ulam.math.luc.edu";
	    //String desthost = "ulam.math.luc.edu";
	    //String desthost = "localhost";

	    InetAddress dest;
        System.err.print("Looking up address of " + desthost + "...");
	    try {
	        dest = InetAddress.getByName(desthost);
	    }
	    catch (UnknownHostException uhe) {
	        System.err.println("unknown host: " + desthost);
	        return;
	    }
	    System.err.println(" got it!");

	    Socket s;
	    try {
		s = new Socket(dest, destport);
	    }
	    catch(IOException ioe) {
		System.err.println("no socket available");
	 	return;
	    }

	    OutputStream sout;

	    try {
	        sout = s.getOutputStream();
	    }
	    catch (IOException ioe) {
	        System.err.println("no socket available");
	        return;
	    }

	    //============================================================

	    while (true) {
		String buf;
		try {
	            buf = bin.readLine();
	        }
	        catch (IOException ioe) {
	            System.err.println("readLine() failed");
	            return;
	        }

	    if (buf == null) {
			//System.err.println("null string!");
			break;
		}

		buf = buf.concat("\n");	// protocol says client supplies newline

		byte[] bbuf = buf.getBytes();

	        try {
	            sout.write(bbuf);
	        }
	        catch (IOException ioe) {
	            System.err.println("write() failed");
	            return;
	        }

	    } // while

	    System.err.println("closing");
	    try {
	       s.close();
	   } catch (IOException ioe) {
		   System.err.println("socket close failed");
		   return;
	   }	   /* */
        //winwait();
    }
}

