All pastes #402373 Raw Edit

froggy

public java v1 · immutable
·published 2007-03-19 21:37 UTC
rendered paste body
import java.net.*;import java.io.*;public class ArrayClient {	public static void main (String [] args) 		{			try {					if (args.length != 2) {							throw new Exception("Usage: java ArrayClient <port> <host address>");						}					int port = Integer.parseInt(args[0]);						Socket connection = new Socket(args[1], port);						OutputStream stream = connection.getOutputStream();								for (int i = 0; i < 5; i++) {								byte[] newArray = buildArray();								stream.write(newArray);								System.out.print("Array ");								for (int j = 0; j < newArray.length; j++) {									System.out.print(newArray[j]);								}								System.out.println( " sent.");							}				stream.flush();		connection.close();				} catch (Exception e) {						System.out.println(e.getMessage());				}			}		public static byte[] buildArray() {				int randomLength = (int)(Math.random()*100);				byte [] byteArray = new byte[randomLength];				byteArray[0] = 0;					for (int i = 1; i < byteArray.length-1; i++) {							byteArray[i] = 1;						}				return byteArray;			}}