- Someone
- Sunday, January 14th, 2007 at 4:57:41am MST
- /*
- * 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.");
- }
- }
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.