All pastes #879975 Raw Edit

Something

public text v1 · immutable
#879975 ·published 2008-01-29 18:49 UTC
rendered paste body
import java.net.*;
import java.io.*;
import java.util.concurrent.*;
import java.nio.channels.*;
import java.lang.*;

public class hw1_client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Kazan's Slow boring Java network directory listing client.");
		System.out.println("Usage: java hw1_client <server address>");
		
		try {
			Socket cl_socket = new Socket("localhost", 9877);
			DataOutputStream outToServer = new DataOutputStream(cl_socket.getOutputStream());
			DataInputStream inFromServer = new DataInputStream(cl_socket.getInputStream());
			String readstr;

			while (true)
			{
				readstr = inFromServer.readLine();
				if (readstr != "$READY$")
				{
					System.out.println("Received OK to proceed from server.");
					break;
				}
			}
			
			outToServer.writeChars("/home/Kazan\n");
			outToServer.flush();

			while (true)
			{
				readstr = inFromServer.readLine();
				if (readstr != "$END$" || readstr == null)
					break;
				System.out.println(readstr);
			}
			outToServer.writeChars("STOP SERVER\n");
			outToServer.flush();

		}
		catch (IOException e)
		{
			System.out.println(e);
		}
	}

}