Professional Documents
Culture Documents
COM:
Developed by microsoft in 1993 which is an interface to design sw components. It
helps in intercommunication irrespective of any programming language.
It provides effective communication between components. Provides reusability of
code just like modules.
Also used in the creation of dynamic objects with certain binary standards and also
creates pointers.
DCOM:
Designed for distributed applications. It was also called as “Network OLE”
before.it came into existence to serve the needs not fulfilled by COM.
It helps remote object to run by ORPC protocol.10 million people use of
Windows every day in networked environments DCOM
Supports dynamic object creation and activation and help components
engage with each other.
It has garbage collector that enhances cpu utilization.
Just as the name suggests, RPC calls procedures on remote systems and is designed to perform
synchronous as well as asynchronous interactions between applications or systems.
3] Database Middleware
Database middleware is a type of middleware that allows direct access to databases. It is designed to
provide direct interaction with databases, and offers multiple database gateways and options for
connectivity.
Sharing flight information between airlines and travel sites. Using Google Maps in a rideshare app.
5] Object Middleware
Also referred to as “Object Request Broker (ORB)“, Object middleware is designed to manage
communication between all objects in a distributed computing system. Sends and receives objects in
an object oriented system.
The purpose of Transaction Processing (TP) Middleware is used in transaction processing monitors.
Its purpose is to provide the environment for development and deployment of disparate
applications. It also encompasses web-application servers.
RPC:
Remote Procedure Call (RPC) is a communication technology that is used by one
program to make a request to another program for utilizing its service on a network without
even knowing the network’s details.
A function call or a subroutine call are other terms for a procedure call.
It is based on the client-server concept. The client is the program that makes the
request, and the server is the program that gives the service.
Working Procedure for RPC Model:
The process arguments are placed in a precise location by the caller when the procedure
needs to be called.
Control at that point passed to the body of the method, which is having a series of
instructions.
The procedure body is run in a recently created execution environment that has
duplicates of the calling instruction’s arguments.
The call to a procedure is possible only for those procedures that are not within the
caller’s address space because both processes (caller and callee) have distinct address
space and the access is restricted to the caller’s environment’s data and variables from
the remote procedure.
The caller and callee processes in the RPC communicate to exchange information via the
message-passing scheme.
The first task from the server-side is to extract the procedure’s parameters when a
request message arrives, then the result, send a reply message, and finally wait for the
next call message.
Only one process is enabled at a certain point in time.
The caller is not always required to be blocked.
The asynchronous mechanism could be employed in the RPC that permits the client to
work even if the server has not responded yet.
In order to handle incoming requests, the server might create a thread that frees the
server for handling consequent requests.
RMI:
Defining a remote interface
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
Creating Stub and Skeleton objects from the implementation class using rmic (RMI
compiler)
Start the rmiregistry
Create and execute the server application program
import java.rmi.*;
import java.net.*;
public class Addserver{
public static void main(String[] args) {
try{
rmiimplementation locobj=new rmiimplementation();
Naming.rebind("rmi:///addition", locobj);
}
catch(RemoteException re){
re.printStackTrace();
}
catch(MalformedURLException mfe){
mfe.printStackTrace();
}
}
}
import java.rmi.*;
import java.net.*;
import java.io.*;
import java.util.*;
}
catch(RemoteException re){
re.printStackTrace();
}
catch(NotBoundException nbe){
nbe.printStackTrace();
}
catch(MalformedURLException mfe){
mfe.printStackTrace();
}
}
}
Whenever a client invokes a method that accepts parameters on a remote object, the parameters
are bundled into a message before being sent over the network. These parameters may be of
primitive type or objects. In case of primitive type, the parameters are put together and a header is
attached to it. In case the parameters are objects, then they are serialized. This process is known
as marshalling.
At the server side, the packed parameters are unbundled and then the required method is invoked.
This process is known as unmarshalling.
RMI Registry
RMI registry is a namespace on which all server objects are placed. Each time the server creates an
object, it registers this object with the RMIregistry (using bind() or reBind() methods). These are
registered using a unique name known as bind name.
To invoke a remote object, the client needs a reference of that object. At that time, the client
fetches the object from the registry using its bind name (using lookup() method).
Client program:
// A Java program for a Client
import java.net.*;
import java.io.*;
public class Client
{
// initialize socket and input output streams
private Socket socket = null;
private DataInputStream input = null;
private DataOutputStream out = null;
// constructor to put ip address and port
public Client(String address, int port)
{
// establish a connection
try
{
socket = new Socket(address, port);
System.out.println("Connected");
// takes input from terminal
input = new DataInputStream(System.in);
// sends output to the socket
out = new
DataOutputStream(socket.getOutputStream());
}
catch(UnknownHostException u)
{
System.out.println(u);
}
catch(IOException i)
{
System.out.println(i);
}
// string to read message from input
String line = "";
// keep reading until "Over" is input
while (!line.equals("Over"))
{
try
{
line = input.readLine();
out.writeUTF(line);
}
catch(IOException i)
{
System.out.println(i);
}
}
// close the connection
try
{
input.close();
out.close();
socket.close();
}
catch(IOException i)
{
System.out.println(i);
}
}
public static void main(String args[])
{
Client client = new Client("127.0.0.1", 5000);
}
}
Server program:
// A Java program for a Server
import java.net.*;
import java.io.*;
public class Server
{
//initialize socket and input stream
private Socket socket = null;
private ServerSocket server = null;
private DataInputStream in = null;
// constructor with port
public Server(int port)
{
// starts server and waits for a connection
try
{
server = new ServerSocket(port);
System.out.println("Server started");
System.out.println("Waiting for a client ...");
socket = server.accept();
System.out.println("Client accepted");
// takes input from the client socket
in = new DataInputStream(
new BufferedInputStream(socket.getInputStream()));
String line = "";
// reads message from client until "Over" is sent
while (!line.equals("Over"))
{
try
{
line = in.readUTF();
System.out.println(line);
}
catch(IOException i)
{
System.out.println(i);
}
}
System.out.println("Closing connection");
// close connection
socket.close();
in.close();
}
catch(IOException i)
{
System.out.println(i);
}
}
public static void main(String args[])
{
Server server = new Server(5000);
}
}
import java.net.*;
import java.io.*;
class MyClient{
public static void main(String args[])throws Exception{
Socket s=new Socket("localhost",3333);
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str="",str2="";
while(!str.equals("stop")){
str=br.readLine();
dout.writeUTF(str);
dout.flush();
str2=din.readUTF();
System.out.println("Server says: "+str2);
}
dout.close();
s.close();
}}
server:
import java.net.*;
import java.io.*;
class MyServer{
public static void main(String args[])throws Exception{
ServerSocket ss=new ServerSocket(3333);
Socket s=ss.accept();
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str="",str2="";
while(!str.equals("stop")){
str=din.readUTF();
System.out.println("client says: "+str);
str2=br.readLine();
dout.writeUTF(str2);
dout.flush();
}
din.close();
s.close();
ss.close();
}}
if(data(receiveData).toString().equals("stop")){
System.out.println("Exiting..");
serverSocket.close();
break;
}
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence=sc.nextLine();
if(capitalizedSentence.equals("stop")){
break;
}
// String capitalizedSentence = sentence.toUpperCase();
//Change sentence to Capital letter
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
serverSocket.send(sendPacket);
receiveData = new byte[1024];
sendData = new byte[1024];
//Send Capitalized data back to client
}serverSocket.close();
}
// A utility method to convert the byte array
// data into a string representation.
public static StringBuilder data(byte[] a)
{
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i = 0;
while (a[i] != 0)
{
ret.append((char) a[i]);
i++;
}
return ret;
}
}
Client:
import java.io.*;
import java.net.*;
class UDPClient_2way
{
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
//Client Socket is created
InetAddress IPAddress = InetAddress.getByName("localhost");
//Gets the IP Address
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
while(true){
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
//sends data
DatagramPacket sendPacket = new DatagramPacket(sendData,
sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
if(sentence.equals("stop")){
System.out.println("Exiting..");
clientSocket.close();
break;
}
DatagramPacket receivePacket = new DatagramPacket(receiveData,
receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence = new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
receiveData = new byte[1024];
sendData = new byte[1024];
}clientSocket.close();
}
// A utility method to convert the byte array
// data into a string representation.
public static StringBuilder data(byte[] a)
{
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i = 0;
while (a[i] != 0)
{
ret.append((char) a[i]);
i++;
}
return ret;
}
}
JDBC steps:
Program:
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sam","root","Kaveya1@");
Statement stmt=con.createStatement();
//inserting
//String sql = "INSERT INTO emp VALUES (103, 'Zara')";
// stmt.executeUpdate(sql);
//update
stmt.executeUpdate(sql2);
while(rs.next()) {
System.out.println(rs.getInt(1)+" "+rs.getString(2)); }
con.close();
if(con!=null){
System.out.println("sucess");
catch(Exception e){ System.out.println(e);}
}
}