Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Someone
Sunday, January 14th, 2007 at 4:57:41am MST 

  1. /*
  2.  * The control class.  Will establish connections.  Check
  3.  * for existence.
  4.  *
  5.  */
  6.  
  7. import java.lang.*;
  8. import java.net.*;
  9. import java.io.*;
  10.  
  11. public class control {
  12.  
  13.         /* Initial attributes */
  14.         private Socket sock;
  15.        
  16.         private OutputStream os;
  17.         private DataOutputStream dos;
  18.         private InputStream is;
  19.         private DataInputStream dis;
  20.         public String response = "down";
  21.        
  22.                 public void addServer(String ip) {
  23.                                        
  24.                         try {
  25.                                 /* Establish a connection */
  26.                                 System.out.println("Establishing socket... \n");
  27.                                 sock = new Socket(ip, 8081);
  28.                        
  29.                                 /* Request information from the server */
  30.                                 os = sock.getOutputStream();
  31.                                 dos = new DataOutputStream(os);
  32.                                 dos.writeUTF("alive?");
  33.                                
  34.                                 /* Receive any information, check it. */
  35.                                 is = sock.getInputStream();
  36.                                 dis = new DataInputStream(is);
  37.                                 String input = new String(dis.readUTF());
  38.                                 System.out.println(input);
  39.                        
  40.                                 if (input.equals ("yes")) {
  41.                                         response = "Up";
  42.                                 } else {
  43.                                         response = "Down";
  44.                                 }
  45.                                
  46.                                 /* close the streams and sockets */
  47.                                 os.close();
  48.                                 dos.close();
  49.                                 sock.close();
  50.                                
  51.                        
  52.                         } catch (IOException e) {
  53.                                 System.out.println("Control Socket Failed.");   
  54.                         }
  55.                 }
  56.                
  57.         }

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

worth-right