Cloud Computing
Cloud Computing
Cloud Computing
Practical No-1
Write a program for implementing client & server communication model using TCP.
1) Write a client server based program using TCP to display date and time from server.
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
try{
}catch(Exception e){
System.out.println("Error...."+ e);
Output:
Client program for date & time
package prac1;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
try{
Socket cs=new Socket(InetAddress.getLocalHost(),8004);
BufferedReader br=new BufferedReader(new InputStreamReader(cs.getInputStream()));
String userinput;
while((userinput=br.readLine())!=null) {
System.out.println(userinput);
}
cs.close();
}
catch(Exception e){
System.out.println("error............"+e);
}
}
}
Output:
2) Write a client server based program using TCP to find if the number enter is prime or
not.
Server Program:
package prac1;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
try{
}catch(Exception e){
System.out.println("Error....."+ e);
}
}
}
Output:
Client Program:
package prac1;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;
try{
Socket cs=new Socket("localhost",8001) ;
BufferedReader inf=new BufferedReader(new InputStreamReader(System.in) );
System.out.println("enter a number");
int a=Integer.parseInt(inf.readLine());
}catch(Exception e){
System.out.println("Error......."+ e);
}
}
}
Output:
3) Write a client server based program using TCP to display chatting application between
client and server.
Server program for chat:
package prac1;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
try{
ServerSocket ss=new ServerSocket(8003);
System.out.println("server started");
Socket s=ss.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DataOutputStream out=new DataOutputStream(s.getOutputStream());
DataInputStream in=new DataInputStream(s.getInputStream());
String send,receive;
while((receive=in.readLine())!=null) {
if(receive.equals("STOP"))
break;
}catch(Exception e){
System.out.println("Error......."+ e);
}
}
}
Output:
Client program for chat:
package prac1;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;
Output:
Practical No-2
Write a program for implementing client server communication model using UDP.
1) A client server based program using UDP to find whether the entered number is even or odd .
SERVER PROGRAM TO CHECK ODD OR EVEN NUMBER
package prac2;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
Output:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
Output:
2) A program to implement simple calculator operations like as addition, subtraction,
multiplication & division.
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.StringTokenizer;
DatagramSocket ds;
DatagramPacket dp;
String str, methodName, result;
int val1, val2;
public CalculatorServer() {
try {
ds = new DatagramSocket(1200);
byte b[] = new byte[4096];
while (true) {
dp = new DatagramPacket(b, b.length);
ds.receive(dp);
str = new String(dp.getData(), 0, dp.getLength());
if (str.equalsIgnoreCase("q")) {
System.exit(1);
} else {
StringTokenizer st = new StringTokenizer(str, "
");
int i = 0;
while (st.hasMoreTokens()) {
String token = st.nextToken();
methodName = token;
val1 = Integer.parseInt(st.nextToken());
val2 = Integer.parseInt(st.nextToken());
}
}
System.out.println(str);
InetAddress ia = InetAddress.getLocalHost();
if (methodName.equalsIgnoreCase("add")) {
result = "" + add(val1, val2);
} else if (methodName.equalsIgnoreCase("sub")) {
result = "" + sub(val1, val2);
} else if (methodName.equalsIgnoreCase("mul")) {
result = "" + mult(val1, val2);
} else if (methodName.equalsIgnoreCase("div")) {
result = "" + div(val1, val2);
}
byte b1[] = result.getBytes();
DatagramSocket ds1 = new DatagramSocket();
DatagramPacket dp1 = new DatagramPacket(b1, b1.length,
InetAddress.getLocalHost(), 1300);
System.out.println("result : " + result + "\n");
ds1.send(dp1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
new CalculatorServer();
}
package prac2;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public CalculatorClient() {
try {
InetAddress ia = InetAddress.getLocalHost();
DatagramSocket ds = new DatagramSocket();
DatagramSocket ds1 = new DatagramSocket(1300);
System.out.println("\nRPC Client\n");
System.out.println("Enter method name and parameter like add
34\n");
while (true) {
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String str = br.readLine();
byte b[] = str.getBytes();
DatagramPacket dp = new DatagramPacket(b, b.length, ia,
1200);
ds.send(dp);
dp = new DatagramPacket(b, b.length);
ds1.receive(dp);
String s = new String(dp.getData(), 0, dp.getLength());
System.out.println("\nResult = " + s + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
Output:
Server Output:
Client Output:
3) A program that finds the square, square root, cube and cube root of the entered
number.
Server Program:
package prac2;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.StringTokenizer;
DatagramSocket ds;
DatagramPacket dp;
String str, methodName, result;
int val;
public NumberServer() {
try {
ds = new DatagramSocket(1200);
byte b[] = new byte[4096];
while (true) {
dp = new DatagramPacket(b, b.length);
ds.receive(dp);
str = new String(dp.getData(), 0, dp.getLength());
if (str.equalsIgnoreCase("q")) {
System.exit(1);
} else {
StringTokenizer st = new StringTokenizer(str, "
");
int i = 0;
while (st.hasMoreTokens()) {
String token = st.nextToken();
methodName = token;
val = Integer.parseInt(st.nextToken());
}
}
System.out.println(str);
InetAddress ia = InetAddress.getLocalHost();
if (methodName.equalsIgnoreCase("square")) {
result = "" + square(val);
} else if (methodName.equalsIgnoreCase("squareroot")) {
result = "" + squareroot(val);
} else if (methodName.equalsIgnoreCase("cube")) {
result = "" + cube(val);
} else if (methodName.equalsIgnoreCase("cuberoot")) {
result = "" + cuberoot(val);
}
byte b1[] = result.getBytes();
DatagramSocket ds1 = new DatagramSocket();
DatagramPacket dp1 = new DatagramPacket(b1, b1.length,
InetAddress.getLocalHost(), 1300);
System.out.println("result : " + result + "\n");
ds1.send(dp1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Client Program:
package prac2;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public NumberClient() {
try
{
InetAddress ia = InetAddress.getLocalHost();
DatagramSocket ds = new DatagramSocket();
DatagramSocket ds1 = new DatagramSocket(1300);
System.out.println("\nRPC Client\n");
System.out.println("1. Square of the number - square\n2. Square root
of the number - squareroot\n3. Cube of the number - cube\n4. Cube root of the
number -cuberoot");
System.out.println("Enter method name and the number\n");
while (true)
{
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
byte b[] = str.getBytes();
DatagramPacket dp = new
DatagramPacket(b,b.length,ia,1200);
ds.send(dp);
dp = new DatagramPacket(b,b.length);
ds1.receive(dp);
String s = new String(dp.getData(),0,dp.getLength());
System.out.println("\nResult = " + s + "\n");
} }
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new NumberClient();
}
}
Server Output:
Client Output:
4) A client server based program using UDP to find the factorial of the entered number.
Server Program:
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
Client Program:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
Server Output:
Client Output:
Practical No-3
Multicast Socket example
Server Program:
package prac3;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
for (;;) {
Thread.sleep(10000);
System.out.println("Sending ");
String str = ("This is Dimple Calling ");
data = str.getBytes();
packet = new DatagramPacket(data, str.length(),
address, PORT);
// Sends the packet
socket.send(packet);
} // end for
} catch (Exception e) {
Client Program:
package prac3;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
}
Server Output:
Client Output:
Practical No-4
Write a program to show the object communication using RMI.
A) A RMI based application program to display current date and time.
1. InterDate.java
package prac4;
import java.rmi.Remote;
2. ServerDate.java
package prac4;
import java.rmi.*;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Date;
public class ServerDate extends UnicastRemoteObject implements InterDate {
@Override
public String display() throws Exception {
String str = "";
Date d = new Date();
str = d.toString();
return str;
}
public static void main(String args[]) throws Exception {
ServerDate s1 = new ServerDate();
Naming.bind("DS", s1);
System.out.println("Object registered.....");
}
}
3. ClientDate.java
package prac4;
import java.rmi.Naming;
Output:
B) A RMI based application program that converts digits to words, e.g. 123 will be
converted to one two three.
1. InterConvert.java
import java.rmi.*;
public interface InterConvert extends Remote
{
public String convertDigit(String no) throws Exception;
}
2. ServerConvert.java
import java.rmi.*;
import java.rmi.server.*;
public class ServerConvert extends UnicastRemoteObject implements
InterConvert {
public ServerConvert() throws Exception
{
}
public String convertDigit(String no) throws Exception
{
String str = "";
for(int i = 0; i < no.length(); i++) {
int p = no.charAt(i);
if( p == 48)
{
str += "zero ";
}
if( p == 49)
{
str += "one ";
}
if( p == 50)
{
str += "two ";
}
if( p == 51)
{
str += "three ";
}
if( p == 52)
{
str += "four ";
}
if( p == 53)
{
str += "five ";
}
if( p == 54)
{
str += "six ";
}
if( p == 55)
{
str += "seven ";
}
if( p == 56)
{
str += "eight ";
}
if( p == 57)
{
str += "nine ";
}
}
return str;
}
3. ClientConvert.java
import java.rmi.*;
import java.io.*;
public class ClientConvert
{
public static void main(String args[]) throws Exception {
InterConvert h1 = (InterConvert)Naming.lookup("Wrd"); BufferedReader
br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter a number : \t"); String no = br.readLine();
String ans = h1.convertDigit(no);
System.out.println("The word representation of the entered digit is : " +ans);
}
}
Output:
Practical No-5
Aim: Show the implementation of web services.
A) Implementing “Big” Web Service.
A. Choosing a Container:
1. Choose File > New Project. Select Web Application from the Java Web.
2. Name the project CalculatorWSApplication. Select a location for the project. Click Next.
3. Select your server and Java EE version and click Finish
B. Creating a Web Service from a Java Class
1. Right-click the CalculatorWSApplication node and choose New > Web Service.
2. Name the web service CalculatorWS and type org.me.calculator in Package. Leave Create
Web Service from Scratch selected. If you are creating a Java EE 6 project on GlassFish or
WebLogic, select Implement Web Service as a Stateless Session Bean.
3. Click Finish. The Projects window displays the structure of the new web service and the
source code is shown in the editor area.
Code:
@WebMethod(operationName = "add")
public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
int k = i + j;
return k;
}
4) Consuming the Web Service Now that you have deployed the web service, you need
to create a client to make use of the web service's add method.
1. Client: Java Class in Java SE Application
1. Choose File > New Project. Select Java Application from the Java category. Name the
project CalculatorWS_Client_Application. Leave Create Main Class selected and
accept all other default settings. Click Finish.
2. Right-click the CalculatorWS_Client_Application node and choose New > Web
Service Client. The New Web Service Client wizard opens.
3. Select Project as the WSDL source. Click Browse. Browse to the CalculatorWS web
service in the CalculatorWSApplication project. When you have selected the web
service, click OK.
4. Do not select a package name. Leave this field empty
5. Leave the other settings at default and click Finish. The Projects window displays the
new web service client, with a node for the add method that you created:
6. Double-click your main class so that it opens in the Source Editor. Drag the add node
below the main() method.
7. In the main() method body, replace the TODO comment with code that initializes
values for i and j, calls add(), and prints the result.
public static void main(String[] args) {
int i = 3; int j = 4;
int result = add(i, j);
System.out.println("Result = " + result);
}
8. Surround the main() method code with a try/catch block that prints an exception.
public static void main(String[] args) {
try {
int i = 3;
int j = 4;
int result = add(i, j);
System.out.println("Result = " + result);
} catch (Exception ex) {
System.out.println("Exception: " + ex);
}
}
Output:
B) Implementing Web Service that connects to MySQL database.
Create a table named Books that will store valid books information
i. Choosing a container
Click Finish.
The web service in the form of java class is ready.
@WebService()
@Stateless()
public class BookWS {
/** * Web service operation */
@WebMethod(operationName = "getBookDetails") public
String getBookDetails(@WebParam(name = "isbn") String isbn) {
//TODO write your implementation code here:
}
}
Fill IP address copied from Installation and User name as “root” and Password as “root123”
which we had given during installation and Click on Add.
Then click on Ok
Now Click on New Storage
Select Window File Sharing (CIFS) and click on next
Uncheck Auto generate option Click on Next.
Provide the path of shared windows XP image and enter local pc credential , click on Finish
Click on New VM – and Windows XP SP3
Select ISO file and click on next –
Click on Next –
Uncheck – Start the new VM and click on create now
Now Right click on Windows XP and Start.
Practical No-7
1. Aim: Implement virtualization using VMWare ESXi Server and managing with
vCenter
Steps:
Install ESXi iso in VMWare workstation.
In vSphere create new Virtual Machine. Install Windows XP iso file and open it.
Practical No-8
Aim: Implement Windows Hyper V virtualization
First we have to uninstall vmware software if already installed on computer because the VMware
Workstation installer does not support running on a Hyper-V virtual machine. after uninstalling
vmware we can proceed to next step go to control panel and click on uninstall a program.