All pastes #316238 Raw Edit

Someone

public text v1 · immutable
#316238 ·published 2007-01-14 11:57 UTC
rendered paste body
/* 
 * The control class.  Will establish connections.  Check
 * for existence. 
 *
 */
 
import java.lang.*;
import java.net.*;
import java.io.*;

public class control {

	/* Initial attributes */
	private Socket sock;
	
	private OutputStream os;
	private DataOutputStream dos;
	private InputStream is;
	private DataInputStream dis;
	public String response = "down";
	
		public void addServer(String ip) {
					
			try {
				/* Establish a connection */
				System.out.println("Establishing socket... \n");
				sock = new Socket(ip, 8081);
			
				/* Request information from the server */
				os = sock.getOutputStream();
				dos = new DataOutputStream(os);
				dos.writeUTF("alive?");
				
				/* Receive any information, check it. */
				is = sock.getInputStream();
				dis = new DataInputStream(is);
				String input = new String(dis.readUTF());
				System.out.println(input);
			
				if (input.equals ("yes")) {
					response = "Up";
				} else {
					response = "Down";
				}
				
				/* close the streams and sockets */
				os.close();
				dos.close();
				sock.close();
				
			
			} catch (IOException e) {
				System.out.println("Control Socket Failed.");	
			}
		}
		
	}