CN Lab Manuals 2019 (1) - Converted-1
CN Lab Manuals 2019 (1) - Converted-1
CN Lab Manuals 2019 (1) - Converted-1
ITCP409-COMPUTER NETWORKS
LABORATORY MANUALS
IV SEMESTER
BASIC PROGRAMS
2. 2.1 GENERATE RANDOM PORT NUMBER 11
TCP COMMUNICATION
3. 3.1 ONE WAY COMMUNICATION 15
SOCKET COMMANDS
4.1 ECHO COMMAND 24
4.
4.2 PING COMMAND 28
FILE TRANSFER
5. 5.1 TCP 37
5.2 UDP 41
6. REMOTE COMMAND EXECUTION 44
ERROR CHECKING
7. 7.1 CYCLIC REDUNDANCY CHECK 48
ROUTING
11.1 SHORTEST PATH ROUTING 74
11. 11.2 FLOODING ROUTING 77
Aim
To study the commands of the socket programming.
Sockets
A socket is one end-point of a two-way communication link between two programs running on
the network. Socket classes are used to represent the connection between a client program and a server
program.
The java.net package provides two classes--Socket and ServerSocket--that implement the
client side of the connection and the server side of the connection, respectively.
They connect to them on published ports when the ServerSocket created it will register itself
with the system as having an internet in client connection. The constructor for the ServerSocket having
client‟s connection it can leave pending before it should be refers connections.
Port
The TCP and UDP protocols use ports to map incoming data to a particular process running on a
computer. Port numbers range from 0 to 65,535 because ports are represented by 16-bit numbers. The
port numbers ranging from 0 - 1023 are restricted; they are reserved for use by well-known services
such as HTTP and FTP and other system service (called well-known ports).
TCP/IP Protocol
TCP provides a point-to-point channel for applications that require reliable communications.
The Hypertext Transfer Protocol (HTTP), File Transfer Protocol (FTP), and Telnet are all examples of
applications that require a reliable communication channel. The order in which the data is sent and
received over the network is critical to the success of these applications. When HTTP is used to read
from a URL, the data must be received in the order in which it was sent. Otherwise, you end up with a
jumbled HTML file, a corrupt zip file, or some other invalid information.
Stream Communication
The stream communication protocol, transfer control protocol, TCP is a connection-oriented
protocol. In order to do communication over the TCP protocol, a connection must first be established
between the pair of sockets. While one of the sockets listens for a connection request (server), the other
asks for a connection. Once two sockets have been connected, they can be used to transmit data in both
directions.
UDP
The UDP protocol provides for communication that is not guaranteed between two applications on
the network. UDP is not connection-based like TCP. Rather, it sends independent packets of data,
called datagrams, from one application to another. Sending datagrams is much like sending a letter
through the postal service: The order of delivery is not important and is not guaranteed, and each
message is independent of any other.
Datagram Communication
The datagram communication protocol, user datagram protocol, is a connectionless protocol,
meaning that each time you send datagrams, you also need to send the local socket descriptor and the
receiving socket‟s address.
CONSTRUCTOR DESCRIPTION
Socket(String host, int port) Connect to the specified server at the specified port.
Socket(InetAddress host, int port) The host is denoted by an inetaddress object.
Socket(String host, int port, Connects to the specified host and port, creating a socket
InetAddresslocalAddress, intlocalPort) on the local host at the specified address and port.
Socket(InetAddress host, int port, The host is denoted by an inetaddress object instead of a
InetAddresslocalAddress, intlocalPort) String
Creates an unconnected socket. Use the connect()
Socket() method
to connect this socket to a server.
METHODS DESCRIPTION
Connects the socket to the specified host. This method is needed
connect(SocketAddress host,
only when you instantiated the Socket using the no-argument
int timeout)
constructor.
Returns the address of the other computer that this socket is
InetAddressgetInetAddress()
connected to.
getPort() Returns the port the socket is bound to on the remote machine.
getLocalPort() Returns the port the socket is bound to on the local machine.
Closes the socket, which makes this Socket object no longer
close()
capable of connecting again to any server.
Address Types
Unicast
An identifier for a single interface. A packet sent to a unicast address is delivered to the
interface identified by that address.
Multicast
An identifier for a set of interfaces (typically belonging to different nodes). A packet sent to a
multicast address is delivered to all interfaces identified by that address.
METHODS DESCRIPTION
InetAddressgetByAddress(byte[] addr) Returns an InetAddress object given the raw IP address.
InetAddressgetByAddress(String host, Create an InetAddress based on the provided host name
byte[] addr) and IP address.
InetAddressgetByName(String host) Determines the IP address of a host, given the host's
name.
getHostAddress() Returns the IP address string in textual presentation.
getHostName() Gets the host name for this IP address.
InetAddressInetAddressgetLocalHost() Returns the local host.
Aim
To write a java program to generate random port number.
Algorithm
1. Start the program
2. Import the java.net and java.iopackages.
3. Declare a new class called RandomPort.
4. Inside RandomPort, declare an object of class ServerSocket, called “server”, with port number 0.
5. Display a message saying which port the object “server” runs on by getting the port number
using the method getLocalPort().
6. Catch and handle any exceptions thrown.
7. Stop the program
Source Code
import java.net.*;
import java.io.*;
class RandomPort
{
public static void main(String args[]) throws IOException
{
System.out.println("GENERATING RANDOM PORT NUMBERS");
// Create a server socket bound to the specified port
ServerSocket Server = new ServerSocket(0);
// ServerSocket Server = new ServerSocket(65536); /* port range out of range
exception */
//Returns the port the socket is bound to on the local machine
System.out.println("This server runs on port "+ Server.getLocalPort());
}
}
Result
Thus the Random Port Number generated program is executed and output verified.
Aim
To write a java program for Finding an IP address of client.
Algorithm
1. Start the program
2. Import the java.net, java.io, and java.util packages.
3. Declare a new class called “IPAddress”.
4. Create an object for the InetAddress Method to get the LocalHost IP Address.
5. Display the message received, which is the local host Inet Address.
6. Stop the program
Source Code
import java.net.*;
import java.io.*;
class IPAddress
{
public static void main(String args[])throws UnknownHostException
{
System.out.println("DISPLAYING HOST NAME & IP ADDRESS");
// InetAddress to get the IP address of any host
// InetAdddress containing local host name and address
InetAddress ip = InetAddress.getLocalHost();
System.out.println("Host Name & IP Address : " + ip);
Result
Thus the java program for Finding IP address of the system has been executed and successfully.
Aim
To write a java program for one way communication using TCP.
Algorithm
Server Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “Server”.
4. Within class “Server”, create a ServerSocket object called “ss” with the port number 8000.
5. Create a Socket object called “soc” by using the accept() method, which listens for a connection
to be made to this server socket and accepts it.
6. Create a new Scanner object, which acts as an input stream to the server from the client.
7. Create a new PrintStream object, which acts as an output stream to the client from the server.
8. Display the message “Server ready...” on the server window.
9. Repeat the following steps:
a) Prompt for the message to be sent from server to client.
b) Read in the message to be sent from the user.
c) Send the message to the client using the PrintStream object.
d) If the message equals the string “bye”, then close the input and output streams and exit
the loop.
10. Stop
Client Program
1. Start
2. Import the java.net, java.io, and java.util packages.
3. Create a new class called“Client”.
4. Inside “Client”, create a new Socket object called “soc” with port number 8000.
5. Create a new Scanner object which acts as the input stream to the client from the server.
6. Repeat the following steps:
a) Read in the input from the server to the client using the Scanner object.
b) Display the message received.
c) If the string received equals “end”, then close the input and output streams and exit the loop.
7. Stop
Client Side
Result
Thus the java for TCP One way communication has been executed successfully.
Aim
To write a java program for two way communication using TCP.
Algorithm
Server Program
1. Start
2. Import the java.net and java.iopackages.
3. Create a new class called“TwoServer”.
4. Inside class “TwoServer”, create a new ServerSocket object called “ss” with the port number 8000.
5. Create a new Socket object called “ss” by using the accept() method, which listens for a
connection to be made to this server socket and accepts it.
6. Create a new PrintStream object which acts as an output stream from the server to the client.
7. Create a new Scanner object which acts as an input stream from the client to the server.
8. Display the prompt “Server isready”.
9. Repeat the following steps:
a) Prompt and read in the message from the user to be sent to the client from the server.
b) Send the message to the client using the PrintStream object.
c) If the message equals the string “bye”, then close the input and output streams and exit the loop.
d) Else, read in the message from the client using the Scanner object.
e) Display the message received from the client to the user.
f) If the message received equals the string “bye”, then close the input and output streams and
exit the loop.
10. Stop.
Source Code
TwoServer.java
import java.net.*;
import java.io.*;
import java.lang.*;
import java.util.*;
class TwoServer
{
public static void main(String a[])throws IOException
{
String str, str1;
ServerSocket ss = new ServerSocket(8000);
// Opens the socket
Socket soc = ss.accept();
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
Scanner in = new Scanner(new Scanner(new InputStreamReader(System.in)));
System.out.print("Server ready \n");
try
{
while(true)
{
System.out.print("Server: ");
TwoClient.java
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
class TwoClient
{
public static void main(String a[])throws IOException
{
String str,str1;
// Creates object for socket
Socket soc = new Socket("LocalHost",8000);
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
}
}
Server Side
Client Side
Result
Thus the program for two way communication using TCP executed and verified.
Aim
Algorithm
Server Program
1. Start
2. Import the java.net and java.io packages.
3. Declarea new class called “EchoServer”.
4. Inside “EchoServer”, declare a ServerSocket class object called “ss” with port number 9000.
5. Create a new Socket object called “soc” using the accept() method.
6. Create a new Scanner object which acts as an input stream from the client to the server.
7. Create a new PrintStream object which acts as an output stream to the client from the server.
8. Repeat the following steps:
i) Read in the message from the client using the Scanner object.
ii) If the received message is equal to the string “end” then close the input and output streams and
exit the program.
iii) Else, display the message received from the client to the server console.
iv) Send the same message back to the client using the PrintStream object.
v) Display “Message sent successfully.”
9. Stop
Client Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “EchoClient”.
4. Inside “EchoClient”, create a new Socket object called “s” with the port number 9000.
5. Create a new Scanner object that acts as an input stream to the client from the server.
6. Create another Scanner object that acts as an input stream from the user to the client.
7. Create a new PrintWriter object that acts as an output stream from the client to the server.
8. Create a new String object called “str”.
9. Display “Echo-Client”.
10. Repeat the following steps:
i) Prompt and read in the message to be sent to the server, from the user, using the
appropriate Scanner object and store in“str”.
ii) Send the message stored in “str” to the server using the PrintWriter object.
iii) Flush the output stream to the server.
iv) If “str” is equal to the string “end”, then close the input and output streams and exit the program.
Source Code
EchoServer.java
import java.net.*;
import java.io.*;
import java.util.*;
public class EchoServer
{
public static void main(String args[]) throws IOException
{
tr
y
{
String str;
ServerSocketss=newServerSocket(9000);
Socket soc = ss.accept();
Scanner socIn = new Scanner(new
InputStreamReader(soc.getInputStream())); PrintStream socOut = new
PrintStream(soc.getOutputStream()); System.out.println("Server Ready.
...........................................................");
while(true)
{
str = socIn.nextLine();
socOut.println(str);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Client Side
Result
Thus data from client to server is echoed back to the client executed and output is verified.
Aim
To implement java program for check connection between client and server using ping command.
Algorithm
Server Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “PingServer”.
4. Inside “PingServer”, declare a ServerSocket object called “sersoc” with port number 9999.
5. Create a new String object called “str”.
6. Create a new Socket object called “soc” using the accept() method.
7. Create a new Scanner object which acts as an input stream from the client to the server.
8. Create a new PrintStream object which acts as an output stream to the client from the server.
9. Display “Ping Server”.
10. Repeat the following steps for integer variable i=0 , 1, …, 4
i) Read in the message from the client using the Scanner object and store in “str”.
ii) Display “Pinged by client”.
iii) Send the message “bytes=3< time<1ms TTL=128” to the client using the
PrintStream object.
11. Close the input and output streams and close the ServerSocket object.
12. Stop
Client Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “PingClient”.
4. Inside “PingClient”, declare the integer variables “i”.
5. Create a Scanner object that acts as an input stream from the user to the client.
6. Prompt and read in the IP address from the user.
7. Create a new Socket object called “soc” with the IP address from the user and port number 9999.
8. Create a new Scanner object that acts as an input stream to the client from the server.
9. Create a new PrintWriter object that acts as an output stream from the client to the server.
10. Display “Pinging ip address with byte=32bytes of data.”
11. Create a new String object called “str”.
12. Repeat the following steps for i=0 , 1, …, 4
i) Send the IP address received from the user to the server using the PrintWriter object.
ii) Flush the output stream to the server.
Source Code
PingServer.java
import java.io.*;
import java.net.*;
import java.util.*;
public class PingServer
{
public static void main(String args[]) throws IOException
{
String str;
int i;
System.out.println("Ping Server");
try
{
ServerSocket sersoc = new ServerSocket(9999);
Socket soc = sersoc.accept();
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
for(i = 0; i < 4; i++)
{
str = socIn.nextLine();
System.out.println("Pinged by client");
socOut.println(str + " Reply from host:bytes=3<time<1ms TT<=128");
}
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}
Server Side
Result
Thus the program for connection availability between client and server using ping command is
executed and verified.
Aim
To implement java program for message passing between client and server using talk command.
Algorithm
Server Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “TalkServer”.
4. Inside “TalkServer( )” constructor, declare a ServerSocket object called “ss” with port
number 9999.
5. Display “Talk Server” and “Node Succesfully Connected..”
6. Create a new Socket object called “soc” using the accept() method.
7. Create a new PrintStream object which acts as an output stream to the client from the server.
8. Create a new Scanner object that acts as an input stream to the server from the client.
9. Create another Scanner object which acts as an input stream from the user to the server.
10. Create a new String objects are called “str1 and str2”.
11. Repeat the following steps:
i) Read in the message from the client using the correct Scanner object and store in “str1”.
ii) Display the message received from the client in “str1”.
iii) If string in “str2” equals “bye” while ignoring case, then close the input and output
streams, close the ServerSocket object, and exit the program.
iv) Else, Prompt and read in the message to send to the client from the user using the
correct Scanner object and store in“str2”.
v) Send the message in “str2” to the client using the PrintStream object.
12. Stop
Client Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “TalkClient”.
4. Inside “TalkClient()” constructor, create a new Socket object called “soc” with the port
number 9999.
5. Display “Talk Client”.
6. Create a new Scanner object that acts as an input stream from the user to the client.
7. Create a new PrintStream object that acts as an output stream from the client to the server.
8. Create a new Scanner object that acts as an input stream to the client from the server.
9. Create a new String object called “str”.
Source Code
TalkServer.java
import java.io.*;
import java.net.*;
import java.util.*;
public class TalkServer
{
public static void main(String args[])throws IOException
{
tr
y
{
String str1,str2;
ServerSocket ss= new ServerSocket(9999);
Socket soc = ss.accept();
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
System.out.println("TALK SERVER");
System.out.println("----------------------");
System.out.println("Node Successfully connected..");
while(true)
{
str1 = socIn.nextLine();
System.out.println("Message Received");
System.out.println("Message : "+str1);
Scanner In = new Scanner(new InputStreamReader(System.in));
str2 = In.nextLine();
if(str2.equals("bye"))
{
break;
}
socOut.println(str2);
TalkClient.java
import java.io.*;
import java.net.*;
import java.util.*;
public class TalkClient
{
public static void main(String args[]) throws IOException
{
tr
y
{
String str;
Socket soc = new Socket("localhost",9999);
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
Scanner keyIn = new Scanner(new InputStreamReader(System.in));
System.out.println("TALK CLIENT");
System.out.println("--------------------");
while(true)
{
System.out.println("Send Message to Server: ");
str=keyIn.nextLine();
if(str.equals("bye"))
{
break;
}
socOut.println(str);
socOut.flush();
System.out.println("Message Sent Successfully");
Output
Client Side
Result
Thus the program for message passing between client and server using talk command is executed
and verified.
Aim
To implement a java program for file transfer between two nodes using TCP.
Algorithm
Server Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “FileServer”.
4. Inside “FileServer”, declare a ServerSocket object called “ss” with port number 8000.
5. Declare a new byte array
6. Repeat the following steps:
a. Display “Server is listening...”
b. Create a new Socket object called “s” using the accept() method.
c. Create Scanner object which acts as an input stream from the user to the server.
7. Get the filename and stored into the BufferedReader.
8. Create a new object for class file and readline.
9. Display “Enter the file name”.
10. If File is exists then FileReader read the content until EOF is reached.
11. Display “The file send successfully”.
12. Else Print FileName does‟t exits.
13. Stop
Client Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “FileClient”.
4. Inside “FileClient”, create a new Socket object called “soc” with the port number 8000.
5. Create a Scanner object that acts as an input stream to the client from the user.
6. Create a new String object called “str”.
7. Prompt and read in if the user wants to view the contents of the file, using Buffered Reader
object, and store in new String “str”.
8. Display “the file is received successfully”.
9. Stop
FileClient.java
import java.io.*;
import java.net.*;
import java.util.*;
public class FileClient
{
public static void main(String args[])throws IOException
{
try
{
String str;
Socket soc = new Socket(InetAddress.getLocalHost(),8000);
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
if((str = socIn.nextLine()) != null)
{
System.out.println("The content of the file is");
System.out.println(str);
System.out.println("The file is received successfully");
}
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}
Client Side
Result
Thus the program for file transfer between two nodes using TCP is executed and verified.
Aim
To implement a java program for file transfer between two nodes using UDP.
Algorithm
Server Program
1. Start.
2. Import the java.net and java.iopackages.
3. Declare a new class called “UDPServer”.
4. Create objects for DatagramSocket and DatagramPacket to send the packet from server.
5. Inside “UDPServer”, declare a DatagramSocket object called “dsoc” with port number 1000.
6. Declare a new byte array size of 1024.
7. Cretae a DatagramPacket object called “dp” and assign the bytes and its length.
8. Display the text message.
9. Stop
Client Program
1. Start
2. Import the java.net and java.iopackages.
3. Declare a new class called “UDPClient”.
4. Inside “UDPClient”, create a DatagramSocket object called “dsoc” with the port number 2000.
5. Declare a new byte array size of 1024.
6. Create a FileInputStream object called “fi” and call the file name.
7. Send the corresponding file to UDPServer using send().
8. Stop
Source Code
UDPServer.java
import java.io.*;
import java.net.*;
class UDPServer
{
public static void main(String args[]) throws IOException
{
try
{
while(true)
{
UDPClient.java
import java.io.*;
import
java.net.*; class
UDPClient
{
public static void main(String args[]) throws IOException
{
try
{
int i=0;
byte[] b = new byte[1024];
DatagramSocket dsoc = new
DatagramSocket(2000); FileInputStream fi = new
FileInputStream("abc.txt"); while(fi.available()!=0)
{
b[i]=(byte)fi.read();
i++;
}
fi.close();
dsoc.send(new DatagramPacket(b,i,InetAddress.getLocalHost(),1000));
}
Output
Server Side
Client Side
Result
Thus the program for file transfer between two nodes using UDP is executed and verified.
Aim
To implement the java program for Remote Command Execution.
Algorithm
Server Program
1. Start
2. Import the java.net, java.io, and java.lang packages.
3. Declare a new class called “RCEServer”.
4. Within class “RCEServer”, create an object of class ServerSocket called “ss” with the port
number 1000.
5. Create a Socket object called “soc” using the accept() method.
6. Create an object of class Runtime using the getRuntime() method.
7. Create a new Scanner object which acts as an input stream to the server from the client.
8. Read in the input from the client using the DataInputStream object and store it in string “s”.
9. Display the value of string“str”.
10. Execute the string command stored in “str” using the Runtime object's exec() method.
11. Stop
Client Program
1. Start
2. Import the java.net, java.lang, and java.io packages.
3. Declare a new class called “RCEClient”.
4. Within class “RCEClient”, create a new Socket object called “soc” with the port number 1000.
5. Create a new Scanner object which acts as an input stream from the user to the client.
6. Create a PrintStream object which acts as an output stream from the client to the server.
7. Send the command read from the user to the server using the getOutputStream object.
8. Display “Enter the command”.
9. Print the corresponding command message.
10. Stop
RCEClient.java
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
public class RCEClient {
public static void main(String a[])throws UnknownHostException,IOException
{
Socket soc = new Socket("localhost",1000);
Scanner keyIn = new Scanner(new InputStreamReader(System.in));
// BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
PrintStream socOut = new PrintStream(soc.getOutputStream());
System.out.println("Enter the Command:");
String str = keyIn.nextLine();
socOut.println(str);
}
}
Server Side
Client Side
Notepad
Result
Thus the program Remote Command Execution (calculator and notepad) executed and verified.
Aim
To Implementation of a java program for Cyclic Redundancy Check (CRC) error handling.
Algorithm
1. Start
2. Import the java.net, java.io, and java.util packages.
3. Inside class “crc_gen”, define the main() method to create a new Scanner object to read input
from the user.
4. Prompt for and read in the message bits as a string and convert and store in an integer array “D”.
5. Prompt for and read in the generator bits as a string and convert and store in an integer array “G”.
6. If G[0] equals 0 then display “Invalid generator bits”.
7. Declare arrays “DR”, “rem”, and “transmitMessage” of size the sum of array D's and array G's sizes
minus one.
8. Copy array D into array DR.
9. Display arrays D, G, DR.
10. Copy DR into array rem and call the computeCRC() method.
11. Display the remainder in arrayrem.
12. Ex-or each element of the array rem with array DR and store the elements in array transmitMessage.
13. Display transmitMessage.
14. Prompt for and read in the received message as a String and convert and store as integer in
array transmitMessage.
15. Copy transmitMessage into array rem and call the computeCRC() method.
16. If any of the bits in array rem don't equal zero then display “Message Received with error”
else display “Message received succesfully.”
17. Stop
Compute CRC
1. Start
2. Declare and initialize integer variable “current” to zero.
3. Repeat the following steps:
4. Repeat for i=0 to(g-1):
5. EX-OR rem[current+i] and G[i] and store back in rem[current+i].
6. Increment “current” while rem[current] equals zero and while “current” is less than length of
array “rem”.
7. If the no. of elements after “current” position in array “rem” is less than the length of array “G”,
then exit loop.
8. Return the array “rem”.
9. Stop
System.out.print("Dividend(afterappending0's)are:");
for(i=0; i< div.length; i++)
{
System.out.print(div[i]);
}
System.out.println();
Result
Thus the java program for Cyclic Redundancy Check is executed and output is verified successfully.
Aim
To implement a java program for hamming code using error handling mechanism.
Algorithm
1. Start
2. Import the jav.io.* and java.utilpackages.
3. Inside class “Hamming_code”, define the main() method to create a new Scanner object to read
input from the user.
4. Declare the integer array d, p, c., and integer value, i and dec.
5. Declare array elements for a value as 0.
6. Enter data in bits and check for the condition.
7. Declare and initialize the variablec.
8. Calculating the array value for a1, A2, a4, a8.
9. If the value of c is equal to 1 then, the value of c is incremented.
10. If the c module 2 is equal to zero, the array value is 0 else 1.
11. The above step is repeated for all the array values.
12. The step is expected for „r‟ array and „v‟ array also.
13. The error will be detected and the corrected message is displayed.
14. Stop.
Source Code
Hamming_code.java
import java.io.*;
import java.util.*;
class Hamming_code
{
public static void main(String arg[])
{
int i, dec;
int d[] = new int[7];
int p[] = new int[4];
int c[] = new inT[11];
int r[] = new int[11];
int pr[] = new int[4];
int rd[] = new int[7];
int s[] = new int[4];
for(i=0; i<11;i++)
{
System.out.print(c[i]+ " ");
}
System.out.println("\n");
s[0] =pr[0]^rd[0]^rD[1]^rd[3]^rd[4]^rd[6];
s[1] = pr[1]^rd[0]^rD[2]^rd[3]^rd[5]^rd[6];
s[2] = pr[2]^rd[1]^rd[2]^rd[3];
s[3] = pr[3]^rd[4]^rd[5]^rd[6];
dec = (s[0]*1)+(s[1]*2)+(s[2]*4)+(s[3]*8);
System.out.print("\n");
if(dec == 0)
{
System.out.println("No error");
}
els
e
{
System.out.println("Error is at
"+dec); if(r[dec-1]==0)
r[dec-1]=1;
else
r[dec-1]=0;
}
System.out.print("\n");
System.out.print("Corrected Code Word is: ");
for(i=0;i<11;i++)
{
System.out.print(r[i]+" ");
}
}
}
Result
Thus the java program for Hamming Code is executed and output is verified successfully.
Aim
To write a java program to simulate the one bit sliding window protocol.
Algorithm
Server Program
1. Start
2. Import the packages java.io, java,net and java.io.
3. Declare the class SlidingServer, and create the object for that class.
4. Create the class ServerSocket and create the object with port number 5000.
5. Create the class Socket and create the object soc and use the method accept().
6. Declare the class Scanner and input stream reader and create the object.
7. Using the getInputStream() method, the input from the user is read.
8. Declare the integer variables a and p parse the variable to integer.
9. The frame is sent to the client and waiting for the acknowledgement.
10. Make use of Thread.Sleep()method to pause the sending of frame until acknowledgement is received.
11. Display the message “Received aknowlwdgement frame number”.
12. Stop
Client Program
1. Start
2. Import the packages java.lang, java.net, java.io and java.util.
3. Enter the corresponding ip address or local host to communicate with server.
4. Create the class Socket and object with the port number 5000 for the local host.
5. Declare the class PrintStream and Scanner and create the objects.
6. Using the intger variable str and parse it using the nextline() method.
7. Enter the number of frame need and send the acknowledgement for executed frame.
8. Stop
int i, str, p;
ServerSocketss=newServerSocket(5000);
System.out.println("Server Ready...");
Socket soc = ss.accept();
Scanner socIn = new Scanner(new InputStreamReader(soc.getInputStream()));
PrintStream socOut = new PrintStream(soc.getOutputStream());
p = Integer.parseInt(socIn.nextLine());
for(i = 1; i <= p; ++i)
{
System.out.println("Sending frame no: " + i);
socOut.println(i);
System.out.println("Waiting for acknowledgement");
Thread.sleep(5000);
str = Integer.parseInt(socIn.next());
System.out.println("Received acknowledgement for frame no: " + i + " as " + str);
}
}
catch(IOException e)
{
System.out.println(e);
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
Server Side
Result
Thus the simulation of simulation of sliding window protocol is executed and output verified
successfully.
Aim
To write a java program for socket for HTTP for web page upload and download.
Algorithm
Server Program
1. Start
2. Importthenecessarypackages.
3. Declare the class “HTTPServer”.
4. Inside class “HTTPServer”, read in the command line arguments.
5. Create the class ServerSocket and create the object with port number 4000.
6. Display the message “Server Waiting for Image”.
7. Create the class Socket and create the object soc and use the method accept().
8. Display the message “Client connected”.
9. Using the InputStream and DataInputStream get the input from the Client side.
10. Display the image size.
11. ByteArrayInputStream class allows a buffer in the memory to be used as an InputStream.
12. Use the read method of the Java ImageIO class, and you can open/read images in a variety of
formats (GIF, JPG, and PNG).
13. JFrame class, is a window that has decorations such as a border, a title, and supports
button components that close oriconify the window.
14. The class ImageIcon is an implementation of the Icon interface that paints Icons from Images.
15. The class JLabel can display either text, an image, or both.
16. Stop
Client Program
1. Start
2. Importthenecessarypackages.
3. Declare the class “HTTPClient”.
4. Display the message “Client isrunning”.
5. Create the class Socket and object with the port number 4000 for the local host.
6. Display the message “Reading image from disk”.
7. The BufferedImage subclass describes an Image with an accessible buffer of image data.
8. Creates a ByteArrayOutputStream and copies the bytes to the output, then calls toByteArray().
It handles large files by copying the bytes in blocks of 4KiB.
9. To ImageIO class provides many more static methods for more advanced usages of the Image I/O
API and create a File class and pass as parameter the image file path.
10. The “javax.imageio.ImageIO” is a handy class to read and write image into local system.
Source Code
HTTPServer.java
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class HTTPServer
{
public static void main(String args[]) throws Exception
{
try
{
int len;
ServerSocket ss = new ServerSocket(4000);
System.out.println("Server Waiting for Image");
Socket soc = ss.accept();
System.out.println("Client connected.");
InputStream in = soc.getInputStream();
DataInputStream dis = new DataInputStream(in);
len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
HTTPClient.java
import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class HTTPClient
{
public static void main(String args[]) throws Exception
{
System.out.println("Client is running.");
try
{
Socket soc = new Socket("localhost",4000);
System.out.println("Reading image from disk. ");
BufferedImage img = ImageIO.read(new File("Koala.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
Output
Server Side
Koala.jpg
Result
Thus the java program for socket for HTTP for web page upload and download are executed and
output is verified.
Aim
To implement a java program for RCP (Remote Screen Capture).
Algorithm
Server Program
1. Start
2. Import the packages java.net, java.io, java.awt, java.image and javax.image.io.
3. Declare the class ScreenServer.
4. Inside the main method declare a new object robot, Robot class provides a useful method for
capturing a screenshot.
5. Display the message “Server Ready…”.
6. Create a new object server with a port number 5000.
7. Declare a Socket class object soc which has a accept() method.
8. The screen size as a Rectangle object to display the getScreenSize() as full image.
9. To capture the whole screen using createScreenCapture() method.
10. Assign the size and width of the image.
11. Get outputstream object to send message from client to user.
12. ObjectOutputStream class writes primitive data types and graphs of Java objects to an OutputStream.
13. Here using image io.write the image orig_screen.png is displayed.
14. Then close() and flush() method close all the server, client and out.
15. Stop
Client Program
1. Start
2. Import the packages java.net, java.io, java.awt, java.image and javax.image.io.
3. Declare a new class ScreenClient.
4. Using the Scanner class to get the input as ip address.
5. Using Socket class to create the object soc and with the port no 5000.
6. Create for object input stream as in to get input from server to client.
7. The BufferedImage subclass describes an Image with an accessible buffer ofimage data.
8. The method setRGB() can be used to set the color of a pixel of an already existing image.
9. imageio package, to load images from an external image format into the internal
BufferedImage format used by Java 2D
10. Here close the server and in object using close() method.
11. Stop
/* getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and
default sRGB color space, from a portion of the image data. */
ScreenClient.java
import java.net.*;
import java.awt.*;
import
java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
public class ScreenClient
{
public static void main(String[] args) throws Exception
{
tr
y
{
int x;
String ip;
Scanner keyIn = new Scanner(new InputStreamReader(System.in));
System.out.println("Enter the IP address: ");
ip = keyIn.nextLine();
Socket soc = new Socket(ip, 5000);
ObjectInputStream in = new ObjectInputStream(soc.getInputStream());
Rectangle size = (Rectangle) in.readObject();
int[] rgbData = new int[(int)(size.getWidth() * size.getHeight())];
for (x = 0; x <rgbData.length;x++)
{
rgbData[x] = in.readInt();
P a g e | 72 COMPUTER NETWORKS DEPARTMENT OF IT, FEAT, AU
}
Output
Server Side
Client Side
Result
Thus the implementation of RCP (Remote Screen Capture) are executed and output is verified.
Aim
To implement the java program for Shortest Path Routing (Dijkstra‟s Algorithm) to find the
shortest path between the nodes.
Algorithm
1. Start
2. Import the java.net and java.iopackages.
3. Declare a class called “ShortestPath”.
4. Read in the input from the client using the Scanner object and store it in string “a”.
5. Dijkstra‟s shortest path algorithm computes all shortest path from a single node.
6. It can also be used for the all pairs shortest path problem, by the simple expedient of applying it
N times once to each vertex.
7. Get the number of nodes in the network for which the shortest path is to be calculated.
8. Represent the nodes that are connected by cost value (Number of hopes delay bandwidth, etc.,)
and nodes that are not connected by infinite value in an adjacent matrix.
9. To find the shortest path between node follow the steps as stated below.
a. Initially, T=V, where T= set of nodes and V= nodes for which the shortest path is to be found.
b. At each step of the algorithm the vertex in T with the smallest d value is removed from T.
c. Each neighbor of in T is examined would be shorter than the currently best known path.
10. The last paths that remain between the nodes are the shortest path between the source node and
the destination nodes.
11. Stop
Source Code
ShortestPath.java
import java.net.*;
import java.io.*;
import java.util.*;
class ShortestPath
{
public static void main(String args[]) throws IOException
{
int n,s,d,i,j;
int y=0, sd=9999;
int[] in = new inT[10];
int[][] m = new int[5][5];
int[] dis = new int[10];
while(j<n)
{
System.out.print("\nEnter the distance between [" +i+ "," +(j+1)+"]:");
m[i][j+1] = Integer.parseInt(a.nextLine());
m[j+1][i] = m[i][j+1];
j++;
}
}
for(i=1;i<=n;i++)
{
in[i] = 0;
dis[i] = m[s][i];
if(m[s][i]!=0)
path[i] = s;
}
in[s] = 1;
dis[s] = 0;
for(i=2;i<n;i+
+)
{
for(j=1;j<=n;j++)
{
if(in[j]==0)
{
P a g e | 77 COMPUTER NETWORKS DEPARTMENT OF IT, FEAT, AU
if(dis[j]<sd)
{
sd=dis[j];
y=j;
}
}
}
in[y]=1;
for(j=1;j<=n;j++)
{
if((in[j]==0)&&(m[y][j]!=0))
{
if((dis[y]+m[y][j])<dis[j])
{
dis[j]=dis[y]+m[y][j];
path[j]=y;
}
}
}
}
i=d;
System.out.print("\n");
System.out.println("The Shortest Path is : \n");
System.out.print(" "+d);
while(path[i]!=s)
{
System.out.print("- - -> " +path[i]);
i=path[i];
}
System.out.print("----> ");
System.out.println(s);
System.out.print("\n");
System.out.println("Distance of the Shortest Path is "+dis[d]);
}
}
Result
Thus the finding shortest path routing between two nodes are executed suessfully and output
verified.
Aim
To implement the java program for Flooding Routing protocol.
Algorithm
1. Start
2. Import the java.util and java.iopackages.
3. Declare a class called “Flooding”.
4. Read in the input from the client using the Scanner object and store it in string “br”.
5. Enter the number of nodes innetwork.
6. Make matrix of network n*n put 0 if not connected else 1 if connected.
7. To calculate the maximum life time of a frame.
8. Enter source address i.e. id (1...n) & destination address now algorithm will calculate where packets
will go.
9. Output will be id of nodes where packets will go.
10. Stop
Source Code
Flooding.java
import java.io.*;
import java.util.*;
public class Flooding
{
/* hopCount function will decide the life time for frame to live in network
*/ static int hopCount(int m[][],intn)
{
int i,j,h=0;
for(i=1;i<=n;i+
+)
{
for(j=1;j<=n;j++)
{
h += m[i][j];
}
}
h -= n;
h =((h%2)==0)?(h/2):(h/2+1);
System.out.print(m[i][j]+" ");
}
System.out.println();
}
System.out.println();
}
}
}
}
showNetworkMatrix(network,n);
inth= hopCount(network,n); //h used to count maximum time to live
frame System.out.println("Maxium Life of frame : "+h +"\n");
int c;//just a variable used to determine
error do
{
System.out.print("Enter the source node id :");
c=Integer.valueOf(br.nextLine()); if(c==0||
c>n)
System.out.print("Entered wrong id number not available in network.try again.\n");
}while(c==0||c>n);
Output
Aim
To implement the java program for Muticast Routing protocol.
Algorithm
Multicast Sender
1. Start
2. Import the java.io and java.netpackages.
3. Declare the class “MulticastSender”.
4. Inside class “MulticastSender”, declare thevariables.
5. Creates a datagram socket and binds it with the available Port Number on the localhost machine.
6. Display the message “This is multicast” with counter values.
7. Prompt for and read in a Class D IP Address (Range: 224.0.0.0 – 239.255.255.255).
8. Create an InetAddress object using the getByName() method and the Class D IP Address.
9. Create a new DatagramPacket object with port number 8888 and join the Class D IP Address group.
10. Encapsulate the message in a DatagramPacket object and send the message to the group IP Address.
11. Stop
Multicast Receiver
1. Start
2. Import the java.io and java.netpackages.
3. Declare the class “MulticastReceiver”.
4. Inside class “MulticastReceiver”, declare thevariables.
5. Create an InetAddress object using the getByName() method and the Class D IP Address.
6. Create a new MulticastSocket object with port number 8888 and jointhe Class DIPAddress
group using the joinGroup() method.
7. Encapsulate the message in a DatagramPacket object and receive the message to the group IP Address.
8. Display the message with the IP address.
9. Stop
catch (InterruptedException e)
{
System.out.println(e);
}
}
}
catch (IOException ioe)
{
System.out.println(ioe);
}
MulticastReceiver.java
import java.io.*;
import java.net.*;
public class MulticastReceiver
{
public static void main(String[] args) throws IOException
{
String msg;
byte[] inBuf = new
byte[256]; try
{
//Prepare to join multicast group
MulticastSocket socket = new MulticastSocket(8888);
InetAddress address = InetAddress.getByName("224.2.2.3");
socket.joinGroup(address);
while(true)
{
DatagramPacket inPacket = new DatagramPacket(inBuf, inBuf.length);
socket.receive(inPacket);
msg = new String(inBuf, 0, inPacket.getLength());
System.out.println("From"+inPacket.getAddress()+"Msg:"+msg);
}
}
catch (IOException e)
{
System.out.println(e);
}
}
}
Receiver Side
Result
Thus implementation the java program for Muticast Routing protocol is executed and output
verified.
Aim
To implement the java program using broadcast routing protocol.
Algorithm
Server Program
1. Start
2. Import java.net, java.io and java.utilpackages.
3. Declare a new class called BroadcastServer.
4. Inside the main method declare a new object for datagram socket as soc.
5. Using the Scanner object as in which acts as an inputStreamReader in input.
6. ArrayList class uses a dynamic array for storing the elements.
7. Add() method used to insert the specified element at the specified position index in a list.
8. The message is delievered to the client one by one with the help of the Datagram Packet.
9. Inside the try block declare a get byname () method.
10. To get the address of client by using the port number 5000.
11. Thus display the message as “message successfully sent to client”.
12. Stop
Client Program
1. Start
2. Import java.net, java.io and java.utilpackages.
3. The DatagramSocket and DatagramPacket are initialized with the port no 5000.
4. The message from sender is take as the packet from buffer.
5. Receive the message using DatagramPacketclass.
6. The message is displayed along with the IP address of the server.
7. Stop the program.
catch(Exception e)
{
System.out.println("Error:" + e);
}
}
}
}
Client Side
Result
Thus the implementation of broadcast routing is executed and output verified.
Aim
To write a java program for simulating ARP protocols using TCP
Algorithm
1. Start
2. Import the java.net package.
3. Declare a new class called “ARP”.
4. Create a new object of class InetAddress and initialize it with Local Host IP Address.
5. Display the InetAddress object.
6. Convert the InetAddress object to String object and store in “ip”.
7. Create a new NetworkInterface object and initialize it using the InetAddress object.
8. Create a new byte array “MAC” and initialize it using the getHardwareAddress() method.
9. Create a new StringBuilder object.
10. Repeat the following steps for i = 0 to length of byte array “MAC”:
i. Assign MAC[i] to String“s”.
ii. Convert value in “s” to Integer type and store in integer type variable “j”.
iii. Convert value in “j” to HexString and store in String “sl”.
iv. If “sl” contains more than 2 characters, then get substring of 2 characters from “sl” and store
back in “sl”.
v. If i ≠ 0, then append “-” before the sl value.
vi. Append “sl” to the StringBuilderobject.
11. Display the NetworkInterface name using the method getDisplayName() through
the NetworkInterface object.
12. Display the MAC Address.
13. Stop
Result
Thus the implementation of Address Resolution Protocol are executed and output verified.
Aim
To study the throughput comparison between IEEE 802.3 and 802.11.
Performance Analysis
In the process of protocol designs and deployments, it is important to understand the
performance of the protocol so that the protocol parameters can be tuned to achieve an optimum
operation in an actual network environment. To make the performance analyses tractable, most
presented performance analyses introduce someassumptions to simplify the protocol operation and/or
the traffic arrival process.
As a result, the obtained analytical results may not be realistic and their applications are
somewhat limited.
Two realistic scenarios that may occur in a LAN – the saturation and the disaster scenarios.
1. The saturation scenario represents a continuous overload condition. The results of this scenario
indicate a fundamental limit of a protocol – its worst performance for a given number of stations.
2. As for the disaster scenario, it models the response of a protocol to the recovery (power up) from a
major failure. This situation is likely to occur in a LAN when the shared channel in the network is
temporarily inaccessible due to, for example, a broken cable or a long period of noise.
In the following, the IEEE 802.3 MAC protocol will be analyzed and simulated under the saturation
and the disaster scenarios based on the assumptions given in the above.
Comparing the saturation throughput of the protocol with the two different data frame sizes, it
is evident that the protocol performs better if a larger data frame size is used.The figure also shows that
the performance of IEEE 802.3 drops as the number of stations increases. This performance
degradation is more significant for the case of a shorter data frame.
The results again suggest that the IEEE 802.3 MAC protocol performs reasonably well for a small
population, but poor for a large population of stations in a LAN.
Figure shows the saturation throughput of IEEE 802.11 versus the number of saturated
stations. From the saturation throughput curves, it is evident that with a good selection of CW
parameters, the IEEE
802.11 MAC protocol performs efficiently for a large population of active stations. The
saturation throughput remains over 80% for the case of CWmin=32 and CWmax=256 for as many as
50 saturated stations.
The results shown in Figure again confirm the efficiency of the IEEE 802.11 MAC protocol. For as
many as 50 saturated stations, the recovery process lasts below one second. Even better performance
results are achieved when the four-way handshaking access method is employed.
Result
Thus the study of the throughput comparison between IEEE 802.3 and 802.11 WAS done.
Aim
To study the various the key distributions and certification schemes.
Introduction
For symmetric key cryptography, the trusted intermediary is called a Key Distribution Center
(KDC), which is a single, trusted network entity with whom one has established ashared secret key.
One can use the KDC to obtain the shared keys needed to communicate securely with all other network
entities. For public key cryptography, the trusted intermediary is called a Certification Authority (CA).
A certification authority certifies that a public key belongs to a particular entity (a person or a network
entity). For a certified public key, if one can safely trust the CA that the certified the key, then one can
be sure about to whom the public key belongs. Once a public key is certified, then it can be distributed
from just about anywhere, including a public key server, a personal Web page or a diskette.
Kerberos
Kerberos is an authentication service developed at MIT that uses symmetric key encryption
techniques and a Key Distribution Center. Although it is conceptually the same as the generic KDC, its
vocabulary is slightly different. Kerberos also contains several nice variations and extensions of the
basic KDC mechanisms. Kerberos was designed to authenticate users accessing network servers and
was initially targeted for use within a single administrative domain such as a campus or company.
Thus, Kerberos is framed in the language of users who want to access network services (servers) using
application-level network programs such as Telnet (for remote login) and NFS (for access to remote
files), rather than human-to-human conversant who want to authenticate themselves to each other, the
key (pun intended) underlying techniques remains the same. The Kerberos Authentication Server (AS)
plays the role of the KDC. The AS is the repository of not only the secret keys of all users (so that each
user can communicate securely with the AS) but also information about which users have access
privileges to which services on which network servers. The most recent version of Kerberos (V5)
provides support for multiple Authentication Servers, delegation of access rights, and renewable
tickets.
One of the principle features of public key encryption is that it is possible for two entities to
exchange secret messages without having to exchange secret keys. For example, when Alice wants to
send a secret message to Bob, she simply encrypts the message with Bob's public key and sends the
encrypted message to Bob; she doesn't need to know Bob's secret (i.e., private) key, nor does Bob need
to know her secret key. Thus, public key cryptography obviates the need for KDC infrastructure, such
as Kerberos. Of course, with public key encryption, the communicating entities still have to exchange
public keys.
A user can make its public key publicly available in many ways, e.g., by posting the key on the
user's personal Web page, placing the key in a public key server, or by sending the key to a
correspondent by e-mail. A Web commerce site can place its public key on its server in a manner that
browsers automatically download the public key when connecting to the site. Routers can place their
public keys on public key servers, thereby allowing other browsers and network entities to retrieve
them.
There is, however, a subtle, yet critical, problem with public key cryptography. To gain insight
to this problem, let's consider an Internet commerce example. Suppose that Alice is in the pizza
delivery business and she accepts orders over the Internet. Bob, a pizza lover, sends Alice a plaintext
message which includes his home address and the type of pizza he wants. In this message, Bob also
includes a digital signature. Alice can obtain Bob's public key (from his personal Web page, a public
key server, or from an e-mail message) and verify the digital signature. In this manner Alice makes
sure that Bob (rather than some adolescent prankster) indeed made the order.
This all sounds fine until clever Trudy comes along. Trudy decides to play a prank. Trudy sends
a message to Alice in which she says she is Bob, gives Bob's home address, and orders a pizza. She also
attaches a digital signature, but she attaches the signature by signing the message digest with her (i.e.,
Trudy's) private key. Trudy also masquerades as Bob by sending Alice Trudy's public key but saying
that it belongs to Bob. In this example, also will apply Trudy's public key (thinking that it is Bob's) to
the digital signature and conclude that the plaintext message was indeed created by Bob. Bob will be
very surprised when the delivery person brings to his home a pizza with everything on it! Here, as in
the flawed authentication scenario, the man-in-the-middle attack is the room cause of our difficulties.
For public key cryptography to be useful, entities (users, browsers, routers, etc.) need to know for sure
that they have the public key of the entity with which they are communicating. For example, when
Alice is communicating with Bob using public key cryptography, she needs to know for sure that the
public key that is supposed to be Bob's is indeed Bob's. Binding a public key to a particular entity is
typically done by a certification authority (CA), which validates identities and issue certificates.
Both the International Telecommunication Union and the IETF have developed standards for
Certification Authorities. ITU X.509 specifies an authentication service as well as a specific syntax for
certificates. RFC 1422 describes CA-based key management for use with secure Internet e-mail. It is
compatible with X.509 but goes beyond X.509 by establishing procedures and conventions for a key
management architecture.
Result
Thus the study of the various the key distributions and certification schemes was done.
Aim
To demonstrate design and implementation of e-mail system.
Design
During the design phase the classes identified in object-oriented analysis must be revisited with a
shift focus to their implementation. New classes or attribute and Methods must be an added for
implementation purposes and user interfaces. Theobject-oriented design process consists of the following
activities:
1. Apply design axioms to design classes, their attributes, methods, associations, structure and
protocols Refine and complete the static UML class diagram by adding details to the UML
diagram.
This step consists of following activities.
Refine attributes
Design methods and protocols by utilizing a UML activity diagram to represent the
method‟s algorithms.
Refine associations between classes
Refine class hierarchy and design with inheritance
Iterate and refine again
2. Design the access layer
Create mirror classes: For every business class identified and created. For example, if there are
three business classes, create three access layer classes.
Identify access layer class relationships.
Simplify classes and their relationships: The main goal here is to eliminate redundant classes
and structures.
Redundant classes: Do not keep two classes that perform similar translate results
activities. Simply select one and eliminate the other.
Method classes: Revisit the classes that consist of only one or two methods to see if theycan
be eliminated or combined with existing classes.
Iterate and refine again.
Design the view layer objects by applying the design axioms and corollaries. Built a prototype of the
view layer interface.
Test usability and user satisfaction
Iterate and refine.
Page| 104 COMPUTERNETWORKSLABORATORY DEPARTMENT OF IT, FEAT, AU
3. Iterate refine the whole design process. From the class diagram, you can begin to extrapolate which
classes you will have to build and which existing classes you can reuse. As you do this, also begin
this, also begin thinking about the inheritance structure. If you have several classes that seem
relates but have specific differences. Design also must be traceable across requirements, analysis,
and design from the Requirements model.
Design Axioms
Axioms are a fundamental truth that always is observed to be valid and for which there is no
counter example or exception. Such explains that axioms may be hypothesized form a large number of
observations by nothing the common phenomena shared by all cases; they cannot be proven or
derived, but they can be invalidated by counter examples or exceptions. A theorem is a proposition that
may not be self-evident but can be proven from accepted axioms. If therefore, is equivalent to a law or
principle. A corollary is a proposition that follows from an axioms or another proposition that has been
proven. Again, corollary is shown to be valid or not valid in the same manner as a theorem. In the two
important axioms axiom 1 deals with relationships between system components and axiom 2 deals
with the complexity of design.
Axiom 2: The information axioms that maintain the information content of the design.
AxiomS1 states that, during the design process, as we go from requirement and use case to a system
component, each component must satisfy that requirement without affecting other requirements.
An axiom 2 is concerned with simplicity. Scientific theoreticians often rely on a general rule known as
Occam‟s razor, after William of Occam. He says, “The best theory explains the known facts with a
minimum amount of complexity and maximum simplicity and straightforwardness.”
The best designs usually involve the least complex code but not necessarily the fewest number of
classes or methods. Minimizing complexity should be the goal, because that produces the most easily
maintained and enhanced application. In an object-oriented system, the best way to minimize
complexity is to use inheritance and the systems built in classes and to add as little as possible to what
already is there.
From the two design axioms, many corollaries may be derived as a direct consequence of the axioms.
These corollaries may be more useful in marking specific design decisions, since they can be applied to
actual situations.
Contents
Sequence diagrams commonly contain the following:
Objects
Links
Messages
Like all other diagrams, sequence diagrams may contain notes and constrains
Sequence
: User
Fill Form
valid
response
LoginRequest
valid
response
select
response
compose
response
Add contacts
response
response
Collaboration Diagram
Collaboration is a society of classes, interfaces, and other elements that work together to provide
some cooperative behavior that‟s bigger than the sum of all its parts.
Contents
Collaboration diagrams commonly contain the following:
Objects
Links
Messages
Like all other diagrams, sequence diagrams may contain notes and constrains.
Collaboration
2: valid
5: valid
Register
1: Fill Form
Inbox
Compose
Update
Mail
Profile
Component Diagram
Inbox Compose
Check
User Mail
Database-
JDBC
Contents
Deployment diagram commonly contain the following things:
Nodes
Dependency and association relationships
Like all other diagrams, deployment diagrams may contain notes and constraints.
Deployment diagrams may also contain components, each of which must live on some node.
Deployment diagrams may also contain packages or subsystems, both of which are used to
group elements of your model into largerchunks.
Database Server
MySQL Server
Application Server
J2SE
Server
USER
Web Servlets
Browser Application
Result
Thus to design and implement an email system is executed successfully.