// Copyright © 2002 // John M. Thompson // Boulder, Colorado USA // jt@iwaypublishing.com // http://www.iwaypublishing.com // // A limited right to copy this page for // individual (non-commercial) educational // use only is hereby granted. import java.net.Socket; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class client { /** * Run server first, then in separate cmd shell, run client. *
* Usage (Windows): > java -classpath . client
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static final int PORT = 1789;
public static final String greeting = "Hello, Server. This is Client.";
public static void main( String[] args )
throws IOException, InterruptedException
{
System.out.println( "Client attempting connection - \n" );
java.net.Socket client = null;
try {
// Connect this client to server on known port
client = new Socket( "localhost", PORT );
} catch( Exception e ) {
System.out.println( "Client connection FAILED.\n" );
System.out.println( "Press