Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   network monitoring program (http://www.programmingforums.org/showthread.php?t=12383)

fresher Jan 15th, 2007 10:19 AM

network monitoring program
 
Hi all, is anyone able to help me out with this great task in java pls? I have tried my best but have just hit the brick wall. any responses greatly appreciated.

Below is the specification ( couldnt attach it unfortunately)


:

NETWORK MONITORING PROGRAM

The aim of this project is to create a network monitoring utility that will enable a network engineer / technician to inspect machines on his / her network and check for good operation. You will need to design and implement two programs.

1. The main utility.
2. The client program.

Main utility program.
This program must have a User Graphic Interface, that presents all computers currently attached on the network and allow the user to select and view information about a particular one if he/she so wishes. Also computers on the network should come up with a different icon or colour if there is a particular problem associated with them by the user
of the utility. The main core function of the utility is to communicate with the client program in regular intervals and check for good operation. If the communication cannot be established or the client takes too long to answer or it sends back a predefined message of trouble then the user can identify that this particular machine is problematic.
`------
The client utility’s function is to run in all computers on the network and periodically report back (or upon request) to the main utility computer the status of its operation. The client utility may contain information about the user of the terminal at that particular
moment or simply report back in a set amount of time, indicating otherwise that there is a problem. This utility does not need to have a user interface, it may require however a settings interface if you so wish.

I’m assessed based on the following:

• Graphics Interface
• Networking
• Use of objects, Methods, good understanding of java basics
o Solid use of Java
o Object Oriented Programming principles
o Proper identification of variables
o Flow diagrams
o Simplicity
o Functionality
A FEW HELPFUL TIPS:
• Remember to use Java’s coding conventions.
• Write well-structured and readable code with appropriate comments in the right
places.

hints and tips:
• Keep the fundamentals of Object Orientation in mind when you write your code i.e. reuse objects, don’t write unnecessarily long programs if you can split the work into different classes, try and use constructors to initialize your programs and don’t burden your main class with variable assignments, etc.
• Finally, write small pieces of code and compile them and add functionality to it. It would help, NOT to write your whole program together and then try and compile it and sort out your 1000 or so odd errors yourself while the supervisors are busy looking at someone else’s 2000 odd errors!!!


------------this is my attempt before hitting the brick wall
:

SERVER
//***************************
/*
*
*program description
*author etc
*
*/
//*******************************

// TCP server which sends a message to client - non threaded
import java.io.*;
import java.util.*;
import java.net.*;


public class TCPserverText
{
public static void main(String args[])
{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       
        // port to receive TCP connections
        int receivePort=9000;           
        Socket socket=null;
            try
                {
                  System.out.println("TCP server starting...: IP address "
                      + InetAddress.getLocalHost().toString() + " port " + receivePort );
                     
                  ServerSocket serverSocket = new ServerSocket(receivePort);
                 
                  // Wait for client to connect.
                  socket = serverSocket.accept();                 
                  System.out.println("Client connection detected from IP address " + socket.getInetAddress()
                                  + " port " + socket.getPort());
                                 
                  // open writer to the client and  send  a message
                  PrintWriter pw = new PrintWriter(socket.getOutputStream());
                  pw.println("Hello " + socket.getInetAddress() + " on port " + socket.getPort());
                  //System.out.println("enter text to send to client");
                  // loop sending messages to client
                  while(true)                     
                    try
                      {
                      pw.flush();
                      String line = in.readLine();
                      pw.println(line);
                    }
                    catch (Exception se) {System.err.println("closing connection"); break;}
                  pw.close();
                  serverSocket.close();
                }
               
               
            catch (Exception se) {System.err.println( se); }
        }
}

CLIENT
------
// TCP client which receives a message from  server

import java.io.*;
import java.util.*;
import java.net.*;


        class IPgenerator2
        {
                  String view_host;
                  String accept;
                  int choice;
                String ip = "148.197.67.";
       
                String ipmethd()
                {
       
       
                KeyboardInput in = new KeyboardInput();
       
                for(int i = 1; i < 10; i++) {
                System.out.print(i);
                System.out.print(". ");
                //System.out.print();
                System.out.println(ip + i);
                }
                System.out.println();
               
                //enter a different network id or hit enter to continue
                //to allow user to enter a different netwrok portion
                //hitting enter implies network is same
                       
                //System.out.print("Enter your network part or press enter to proceed: ");
                        //String network = in.readString();
                       
                        //test
                        //.out.println(network);
                       
                        //if enter is pressed - same network
                  //        if("".equals(network))
                        //{
                       
                                System.out.print("SELECT A MACHINE TO VIEW FROM LIST: ");
                                int choice = in.readInteger();
                               
                                       
                               
                        //        }
                        //        else
                       
                                //pass new network part to ip string variable
                        //        ip = network;
                               
               
               
               
                                //real switch
                                switch (choice)
                                  {
               
                                case 1:
                                view_host = "148.197.67.211";
                                //System.out.println("You selected to view machine with IP: " + view_host);
                                //return view_host = "192.168.2.1";
                                break;
       
                                case 2:
                                view_host = "148.197.67.212";
                                //System.out.println("You selected to view machine with IP: " +  view_host);
                                //return view_host = "192.168.2.2";
                                break;
                       
                                case 3:
                                view_host = "148.197.67.213";
                                //System.out.println("You selected to view machine with IP: " +  view_host);
                                //return view_host = "192.168.2.3";
                                break;
                       
                                case 4:
                                view_host = "148.197.67.214";
                                //System.out.println("You selected to view machine with IP: " +  view_host);
                                //return view_host = "192.168.2.4";
                                break;
                       
                                case 5:
                                view_host = "148.197.67.215";
                                //System.out.println("You selected to view machine with IP: " +  view_host);
                                //return view_host = "192.168.2.4";
                                break;
                       
                                case 6:
                                view_host = "148.197.67.216";
                                //System.out.println("You selected to view machine with IP: " +  view_host);
                                //return view_host = "192.168.2.4";
                                break;
                       
       
                                default:
                                System.out.println("This machine doesnt exist, please choose a valid host");
                       
                                //return view_host;
                                }
                               
                          return view_host;
                 
                    }
          }




        //client program starts here

        public class TCPclientText
        {
       
                        public static void main(String args[])
                        {
                        //initialisation
                        String view_host;
                        IPgenerator2 ip = new IPgenerator2();
                       
                        //call ipgenerator
                        //ip.ipmethd();
       
         
                        //server IP address
                          //String remoteIPaddress="192.168.2.4";
                          // int remotePort=9000;
 
 
 
                          //array to hold list of client IPs say registered
                          //array enables me select the client to connect to
                        // String remoteIPaddress[]={"192.168.2.4","192.168.2.5","192.168.2.6"};
                        //call ip generator and assign it
                       
                          String remoteIPaddress =ip.ipmethd();
                          int remotePort=9000;
         
                          //for(int index=0; index<3;index++)
 
                          try
                              {
                        // connect to server with remoteIPaddress on remotePort
                        //Socket socket1 = new Socket( remoteIPaddress, remotePort );
                        //here I have selected to connect to just the first client - index 0
                        Socket socket1 = new Socket( remoteIPaddress, remotePort );
       
       
                        //timeout after 3sec of inactivity
                        //socket1.setSoTimeout(3000);
       
                        // open reader to receive messages from server
                        BufferedReader inFromServer = new BufferedReader(new InputStreamReader( socket1.getInputStream()));
                        System.out.println("Server contacted OK ");
       
       
                        // loop reading messages from server
                        while(true)               
                    {
                   
                    String line = inFromServer.readLine();
                    System.out.println("From server " + line);
                    } 
             
                }
       
                        catch(UnknownHostException e){
                    System.err.println("Don't know about host ....");   
                    }     
       
                //predefined message is returned if server cannot be contacted
                catch(ConnectException e){
            System.err.println("Unreachable node!, failure in connecting to server");
            }   
       
            catch (IOException e) {System.err.println("TCP client error " +  e); }
   
            //if server suddenly shutsdown for instance
   
        }
    }

It mustnt be with the GUI. coding that works will be very helpful indeed.

many thanks for responses in advance pls im stuck...

BinarySurfer Jan 15th, 2007 11:19 AM

So, the client reports its computer's traffic to the main utility, right?

fresher Jan 15th, 2007 11:29 AM

Quote:

Originally Posted by BinarySurfer (Post 122661)
So, the client reports its computer's traffic to the main utility, right?

Yes it reports its traffic, name, Ip and working status (in green). thanks
I just want something that works pls.

Arevos Jan 15th, 2007 12:04 PM

What do you mean by its "traffic"? Also, just to be clear, I take it this is homework or coursework of some kind?

fresher Jan 15th, 2007 12:21 PM

Quote:

Originally Posted by Arevos (Post 122664)
What do you mean by its "traffic"? Also, just to be clear, I take it this is homework or coursework of some kind?

Its not traffic per se perhaps i didnt get what he meant by 'traffic'. it is a group project made up of java newbies.

Arevos Jan 15th, 2007 1:23 PM

Quote:

Originally Posted by fresher (Post 122666)
Its not traffic per se perhaps i didnt get what he meant by 'traffic'. it is a group project made up of java newbies.

Okay, so it just reports on IP, hostname and whether the clients are operational? Do the clients autodetect the server (via some sort of network broadcast) or do you have to explicitly configure each client with the server IP?

fresher Jan 15th, 2007 1:37 PM

Quote:

Originally Posted by Arevos (Post 122669)
Okay, so it just reports on IP, hostname and whether the clients are operational? Do the clients autodetect the server (via some sort of network broadcast) or do you have to explicitly configure each client with the server IP?

Yes it just reports on IP, working condition, etc.....only on request by the network engineer from the main utility. In other words connection is by "handshake" - only one client can connect at a time (no threading is required in order to accept multiple connections). Yes you configure each client with the server ip but i guess you should be able to change the ip depending on the network it runs on. thanks for your posts thus far. Im happy to clarify more please. I'd be glad with something that works simply; not fossy.


PS. The network eng specifies which machine to connect to since all machine will be listening for connection.

Infinite Recursion Jan 16th, 2007 9:58 AM

I wouldn't hardcode the IP addresses in if I were you...


All times are GMT -5. The time now is 1:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC