1 import java.io.BufferedReader;
2 import java.io.BufferedWriter;
3 import java.io.FileNotFoundException;
4 import java.io.FileReader;
5 import java.io.IOException;
6 import java.io.OutputStreamWriter;
7 import java.io.PrintWriter;
8 import java.net.InetAddress;
9 import java.net.Socket;
10 import java.net.UnknownHostException;
16 private static String name ;
17 private static String IP ;
18 private static String path = "/tmp/vm_host_ip" ;
19 private static FileReader fr ;
20 private static String host_ip ;
21 private static String host_port ;
23 public static void main( String argv[] )
25 System.out.println( "Running information program for HpcVm ..." ) ;
27 /** Retrieving informations **/
29 InetAddress ia = InetAddress.getLocalHost() ;
30 name = ia.getCanonicalHostName() ;
31 IP = ia.getHostAddress() ;
32 } catch( Exception e ) {
33 System.err.println( "Error: Unknown Host: " + e ) ;
36 /** Retrieving host informations **/
38 fr = new FileReader( path ) ;
39 } catch( FileNotFoundException e ) {
42 BufferedReader bf = new BufferedReader( fr ) ;
47 line = bf.readLine() ;
48 } catch( IOException e ) {
52 String[] infos = line.split( " " ) ;
56 host_port = infos[1] ;
57 } catch( Exception e ) {
65 } catch( IOException e ) {
70 /** Sending informations to host **/
72 Socket socket = new Socket( host_ip, Integer.parseInt( host_port ) ) ;
74 PrintWriter pw = new PrintWriter( new BufferedWriter(
75 new OutputStreamWriter( socket.getOutputStream() ) ), true ) ;
91 } catch( NumberFormatException e ) {
93 } catch( UnknownHostException e ) {
95 } catch( IOException e ) {
99 System.out.println( "... Ok" ) ;