Sequence diagrams

Where to start?

Page 1 of 1

4 Replies - 2360 Views - Last Post: 04 January 2011 - 04:10 PM Rate Topic: -----

#1 neoleeyennek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-December 10

Sequence diagrams

Posted 04 January 2011 - 01:27 PM

Hey,

Heres the problem i've got, i have completed the program that i want to make but forgot about the uml side of things for other people to understand how the program works. I'm unsure where to start with creating a sequence diagram for the program because of how the program is made. Its functionality is in the main class but the program is spread out in to three class files. Where should i start?

Below is the code of the program

import java.util.Scanner;
import java.util.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.net.*;
import java.io.*;

public class Networktool {

public static void main(String[] args) {

/** Define what mode the program is in by reading a single line from the console and stores into name variable*/
	Scanner in = new Scanner(System.in);
	System.out.print("Enter 1 for client mode or 2 for server mode:");
	int choice;
	choice = in.nextInt();

/**Runs code from Socket client*/
if (choice == 1)
	{
	SocketClient.main(null);           		
	}

/**Runs code from MultipleSocketServer*/
else if (choice == 2)
	{
	MultipleSocketServer.main(null);	   
	}

/**Input choice error message*/
else
	System.out.println("Invalid choice.");
	}
	}




import java.util.Scanner;
import java.util.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.net.*;
import java.io.*;

public class SocketClient {

int port;
long milis1;
long milis2;
long diffSeconds;
long diffMinutes;

public static void main(String[] args) {


   /** Define a host server by reading a single line from the console and stores into name variable */
   String host;
   System.out.println(" ");
   System.out.println("Enter server address");
   Scanner in = new Scanner(System.in);
   host = in.nextLine();


    /** Define a port for connection to the socket*/
    int port = 11337;

    System.out.println(" ");
    System.out.println("Connection initialized");
    System.out.println(" ");
try {
      /** Obtain an address object of the server and Establish a socket connetion  */
    InetAddress address = InetAddress.getByName(host);
    Socket connection = new Socket(address, port);

/** Creates a DateFormat/Calendar object to get the time as the socket is opened and displays it*/
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:ms");
    Calendar cal = Calendar.getInstance();
    System.out.println("Start time : " + dateFormat.format(cal.getTime()));

/** Creates a StringBuffer object */
    StringBuffer instr = new StringBuffer();

/** Creates a BufferedOutputStream object */
    BufferedOutputStream buffos = new BufferedOutputStream(connection.
    getOutputStream());

/** Creates an OutputStreamWriter object */
    OutputStreamWriter outsw = new OutputStreamWriter(buffos);
    String process = "Calling the Server on "+ host + " port " + port +(char) 23;

/** Write across the socket connection and flush the buffer */
    outsw.write(process);
    outsw.flush();

/** Creates a BufferedInputStream object for reading incoming socket streams */

    BufferedInputStream bins = new BufferedInputStream(connection.
    getInputStream());

/**Creates an InputStreamReader for the buffer stream */

    InputStreamReader insr = new InputStreamReader(bins);

/**Reads the socket's InputStream and append to a StringBuffer */
    int c;
while ( (c = insr.read()) != 23)
    instr.append( (char) c);

/** Close the socket connection. */
    connection.close();
    System.out.println(instr);

/** Creates a DateFormat/Calendar object to get the time as the socket is closed and displays it*/
    Calendar cal1 = Calendar.getInstance();
    System.out.println("End time : " + dateFormat.format(cal1.getTime()));
    System.out.println(" ");

/** Puts time from the date/Calendar object in to a long in thw format of milliseconds*/
    long milis1 = cal.getTimeInMillis();
    long milis2 = cal1.getTimeInMillis();

/** Calculate difference in Miliseconds*/
    long diff = milis2 - milis1;

/**Calculate difference in seconds */
    long diffSeconds = diff / 1000 ;
    diffSeconds %= 60;

/**Calculate difference in minutes*/
    long diffMinutes = diff / 1000;
    diffMinutes = diffMinutes / 60;

/**Displays calculated difference*/
    System.out.println("The RTT (Round Trip Differnece) difference is");
    System.out.println(" ");
    System.out.println("Minutes " +diffMinutes);
    System.out.println("Seconds "+diffSeconds);
    System.out.printf("Milliseconds: %tL\n", diff);
    System.out.println(" ");
     }
/**Input and output exception*/
    catch (IOException e) {
      System.out.println("IOException: " + e);
    }
    
  }
}



import java.util.Scanner;
import java.util.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.net.*;
import java.io.*;

public class MultipleSocketServer implements Runnable {
/** Defines varibles which are used in the code*/
	private Socket connection;
	private int ID;
	public static int d;
  int character;

int port;
int count;
	public static void main(String[] args) {
	int delay;
	int port = 11337;
	int count = 0;

try{
/** Creates a ServerSocket object */
	ServerSocket socket1 = new ServerSocket(port);

/** Define if there is a a testing delay in the server by reading a single line from the console and stores into name variable */
	System.out.println("Welcome to the server set up,");
	System.out.println(" ");
	System.out.println("Please enter amount of seconds you want a delay the reply from this server");
	System.out.println(" ");
	System.out.println("Testing purposes enter a number");
	System.out.println(" ");
	System.out.println("If you want to run the server in operational mode enter 0 ");
	System.out.println(" ");
	System.out.println("Then press enter to start up the server");
	System.out.println(" ");
	Scanner scan = new Scanner(System.in);
	delay = scan.nextInt();
	delay = (delay * 1000); 
	d= delay;
while (true) {

/**ServerSocket is integrated into a thread to allow multiple clients to connect to the server on the one socket*/
	System.out.println("Server Initialized");
        Socket connection = socket1.accept();
        Runnable runnable = new MultipleSocketServer(connection, ++count);
        Thread thread = new Thread(runnable);
        thread.start();
	}

/**Error exception*/
	}
catch (Exception e) {}
	}

/**Defines MultipleSocketServer thread id number and the socket that thread uses*/
	MultipleSocketServer(Socket s, int i) {
	this.connection = s;
	this.ID = i;
	}

/**Thread code*/
public void run() {

try {
/** Creates a BufferedInputStream object for reading incoming socket streams */
	BufferedInputStream bufis = new BufferedInputStream(connection.getInputStream());

/**Creates an InputStreamReader for the buffer stream */
	InputStreamReader inpsr = new InputStreamReader(bufis);
	

/** Creates a StringBuffer object */
	StringBuffer process = new StringBuffer();
while((character = inpsr.read()) != 23) {
        process.append((char)character);
	}
	System.out.println(process);

//need to wait defined seconds to pretend that we're processing something
try {
	Thread.sleep(d);
	}
catch (Exception e){}

	String returnCode = "Server reply"+(char) 23;

/** Creates a BufferedOutputStream object */
	BufferedOutputStream bufos = new BufferedOutputStream(connection.getOutputStream());

/** Creates an OutputStreamWriter object */
	OutputStreamWriter outswr = new OutputStreamWriter(bufos);
	outswr.write(returnCode);
	outswr.flush();
	}

/**Error exception*/
catch (Exception e) {
	System.out.println(e);
	}
finally {

/** Close the socket connection. */
try {
	connection.close();
	}

/**Input and output exception*/
catch (IOException e){}
	}
	}
	}



Is This A Good Question/Topic? 0
  • +

Replies To: Sequence diagrams

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2652
  • View blog
  • Posts: 11,191
  • Joined: 20-September 08

Re: Sequence diagrams

Posted 04 January 2011 - 01:35 PM

A sequence diagram traces a path of execution through an app. There may be more than one of these. You should start with the most typical, tracing the methods through which the app runs
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Sequence diagrams

Posted 04 January 2011 - 01:48 PM

I am far from being a UML expert, actually never used it, but I though UML was used to display classes relationship not really data flow.

In your case, your Networktool is just a driver, that runs one of the two other class. You don't even create a Networktool object. This could have been written as a bat file on Windows or a script on Unix. It is just to avoid to your customer to separate syntax to start the Server or the Client.

The only thing you can do is to have a box for it with 2 arrows, one going to the Server box the other to the Client box.
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Re: Sequence diagrams

Posted 04 January 2011 - 02:38 PM

You should read the following article. It will really help you to both write class diagrams and relationships between classes.

http://www.objectmen...assDiagrams.pdf

This post has been edited by Dogstopper: 04 January 2011 - 02:39 PM

Was This Post Helpful? 0
  • +
  • -

#5 neoleeyennek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-December 10

Re: Sequence diagrams

Posted 04 January 2011 - 04:10 PM

This what i think the multipleSocketServer Sequence diagrams should look like. Is this right or have i gone off on a tangent?
Posted Image
Posted Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1