EX - NO: Implementation of Address Resolution Protocol Date: Aim
EX - NO: Implementation of Address Resolution Protocol Date: Aim
EX - NO: Implementation of Address Resolution Protocol Date: Aim
AIM:
ALGORITHM:
Client Side:
Server Side:
import java.io.*;
import java.net.*;
class ArpClient
{
public static void main(String args[])throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String ip;
System.out.println("Enter the IPADDRESS:");
ip=br.readLine();
ps.println(ip);
String str,data;
BufferedReader br2=new BufferedReader(new
InputStreamReader(ss.getInputStream()));
System.out.println("ARP From Server::");
do
{
str=br2.readLine();
System.out.println(str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}
}
ARP SERVER
import java.io.*;
import java.net.*;
class ArpServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br1=new BufferedReader(new
InputStreamReader(s.getInputStream()));
String ip;
ip=br1.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec("arp -a "+ip);
RESULT:
Echo Server
import java.io.*;
import java.net.*;
class EchoServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String str,data;
do
{ System.out.println("Server To LocalHost:");
str=br.readLine();
ps.println(str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}
Echo Client
import java.io.*;
import java.net.*;
class EchoClient
{
public static void main(String args[])throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
BufferedReader br=new BufferedReader(new
InputStreamReader(ss.getInputStream()));
String str,data;
do
{
str=br.readLine();
System.out.println("Echo From Server::"+str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}
OUTPUT
SERVER WINDOW:
C:\Networking Programs>java EchoServer
Server To LocalHost:
hai
Server To LocalHost:
welcome
Server To LocalHost:
how are you
Server To LocalHost:
End
CLIENT WINDOW:
C:\Networking Programs>java EchoClient
Echo From Server::hai
Echo From Server::welcome
Echo From Server::how are you
Echo From Server::end
EX.NO: IMPLEMENTATION OF REMOTE METHOD INVOCATION
DATE :
AIM:
ALGORITHM:
1.Create the rmi interface where the following methods are declared.
2.Implement remote objects at server side which are declared in the rmi
interface.
3. At client side the remote objects are called and their process is
executed.
PROGRAM:
RMI INTERFACE
import java.rmi.*;
public interface rmiInterface extends Remote
{
public int add(float a,float b)throws RemoteException;
public int multiply(int a,int b)throws RemoteException;
public float divide(float a,float b)throws RemoteException;
}
RMI SERVER
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
public class rmiServer extends UnicastRemoteObject implements
rmiInterface
{
public rmiServer()throws RemoteException
{}
public int add(float a,float b)throws RemoteException
{
int c;
c=(int)(a+b);
return(c);
}
public int multiply(int a,int b)throws RemoteException
{
int c;
c=(int)a*b;
return(c);
}
public float divide(float a,float b)throws RemoteException
{ float c;
c=(float)a/b;
return(c);
}
public static void main(String args[])throws Exception
{
try
{ rmiServer rs=new rmiServer();
Naming.rebind(args[0],rs);
}
catch(Exception e)
{ System.out.println("Error"+e);
}}}
RMI CLIENT
import java.io.*;
import java.rmi.*;
public class rmiClient
{
public static void main(String sdfs[])throws Exception
{
try
{
float a,b,c,d;
int e,f;
String rr;
rmiInterface ri=(rmiInterface)Naming.lookup(sdfs[0]);
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
do
{
System.out.println("1.Add()\n2.Multiply()\n3.Divide()\n4.Exit()\nEnter
U'R choice:");
int sw=Integer.parseInt(br.readLine());
switch(sw)
{
case 1:
System.out.println("Enter the First Value");
a=Float.parseFloat(br.readLine());
System.out.println("Enter the Second Value");
b=Float.parseFloat(br.readLine());
System.out.println("The Added Value Is:"+
ri.add(a,b));
break;
case 2:
System.out.println("Enter the First Value");
e=Integer.parseInt(br.readLine());
System.out.println("Enter the Second Value");
f=Integer.parseInt(br.readLine());
System.out.println("The Added Value Is:"+
ri.multiply(e,f));
break;
case 3:
System.out.println("Enter the First Value");
c=Float.parseFloat(br.readLine());
System.out.println("Enter the Second Value");
d=Float.parseFloat(br.readLine());
System.out.println("The Added Value Is:"+
ri.divide(c,d));
break;
case 4:
System.exit(0);
break;
}
System.out.println("Do u Want to Continue 1/0");
rr=br.readLine();
}while(rr.equalsIgnoreCase("1"));
}
catch(Exception e)
{
System.out.println("Error"+e);
}}}
OUTPUT
RESULT:
Thus the implementation of RMI is done & executed
successfully.
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
class clientRCE
{
public static void main(String args[]) throws IOException
{ try {
String str;
Socket client=new Socket("127.0.0.1",6555);
PrintStream ps=new PrintStream(client.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("\t\t\t\tCLIENT WINDOW\n\n\t\tEnter The
Command:");
str=br.readLine();
ps.println(str);
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}}
SERVER PROGRAM:
import java.io.*;
import java.net.*;
class serverRCE
{
public static void main(String args[]) throws IOException
{
try
{ String str;
ServerSocket server=new ServerSocket(6555);
Socket s=server.accept();
BufferedReader br=new BufferedReader(new
InputStreamReader(s.getInputStream()));
str=br.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec(str);
}
catch(IOException e)
{
System.out.println("Error"+e);
}}}
OUTPUT
C:\Networking Programs>java serverRCE
AIM:
To ping the server with its ipaddress.
ALGORITHM:
CLIENT SIDE:
1. Establish a connection between the Client and Server.
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
2. Create instances for input and output streams .
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader ips=new BufferedReader
(newInputStreamReader (ss.getInputStream()));
3. Get the ip address that is to be pinged.
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
ip=br.readLine();
4. Send the message to its output Stream.
ps.println(str);
SERVER SIDE:
1.Accept the connection request by the client.
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
2. Get the ip address sent by the client.
str=ips.readLine();
3. Print the pinging information.
Process p=r.exec("ping "+ip);
PROGRAM:
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
class PingClient
{
public static void main(String args[])throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String ip;
System.out.println("Enter the IPADDRESS:");
ip=br.readLine();
ps.println(ip);
String str,data;
BufferedReader br2=new BufferedReader(new
InputStreamReader(ss.getInputStream()));
System.out.println("Ping From Server::");
do
{
str=br2.readLine();
System.out.println(str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}
SERVER PROGRAM:
import java.io.*;
import java.net.*;
class PingServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br1=new BufferedReader(new
InputStreamReader(s.getInputStream()));
String ip;
ip=br1.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec("ping "+ip);
BufferedReader br2=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String str;
while((str=br2.readLine())!=null)
{
ps.println(str);
}
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}
OUTPUT
C:\Networking Programs>java PingServer
C:\Networking Programs>java PingClient
Enter the IPADDRESS:
192.168.11.57
Ping From Server::
Pinging 192.168.11.57 with 32 bytes of data:
RESULT:
AIM:
To implement TALK using User Datagram Protocol.
ALGORITHM:
SERVER SIDE:
1.Create datagram socket for theclient.
public static DatagramSocket ds;
5.Thus the chatting between client and server is done until server
sends end signal
CLIENT SIDE:
1. Create datagram socket for theclient.
public static DatagramSocket ds;
2. Client receives the datagram sent by the server.
DatagramPacket p=new DatagramPacket(buffer, buffer.length);
ds.receive(p);
3. Client sends the reply to server;
4. Thus the chatting between client and server is done until client
sends end signal
PROGRAM:
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
class SWPClient
{
public static void main(String args[])throws IOException
{
try
{
int client=3000,server=3002;
DatagramSocket ds=new DatagramSocket(client);
DatagramPacket dp;
byte outbuff[]=new byte[1024];
byte inbuff[]=new byte[1024];
String str,data;
DataInputStream dis=new DataInputStream(System.in);
do
{
System.out.println("To Server:");
str=dis.readLine();
outbuff=str.getBytes();
InetAddress ia=InetAddress.getLocalHost();
dp=new DatagramPacket(outbuff,str.length(),ia,server);
ds.send(dp);
System.out.println("From Server:");
dp=new DatagramPacket(inbuff,inbuff.length);
ds.receive(dp);
data=new String(dp.getData(),0,dp.getLength());
System.out.println(data);
}while(!(str.equalsIgnoreCase("end") ||
data.equalsIgnoreCase("end") ));
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}
}
SERVER PROGRAM:
import java.io.*;
import java.net.*;
class SWPServer
{
public static void main(String args[])throws IOException
{
try
{
int client=3000,server=3002;
DatagramSocket ds=new DatagramSocket(server);
DatagramPacket dp;
String str,data;
byte inbuff[]=new byte[1024];
byte outbuff[]=new byte[1024];
do
{
dp=new DatagramPacket(inbuff,inbuff.length);
ds.receive(dp);
str=new String(dp.getData(),0,dp.getLength());
System.out.println("From Client:"+str);
System.out.println("To Client:");
DataInputStream dis=new DataInputStream(System.in);
data=dis.readLine();
outbuff=data.getBytes();
InetAddress ia=dp.getAddress();
int port=dp.getPort();
dp=new DatagramPacket(outbuff,data.length(),ia,port);
ds.send(dp);
}while(!(str.equalsIgnoreCase("end") ||
data.equalsIgnoreCase("end") ));
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}
}
OUTPUT:
SERVER:
CLIENT:
RESULT:
Thus the implementation of TALK is done & executed
successfully.
AIM:
ALGORITHM:
import java.io.*;
class shortestPath
{
int n,infy,s,t,i,n1;
int weight[][]=new int[10][10];
int pd,k,dc;
int prem[]=new int[10];
int distance[]=new int[10];
int current,smalldist,newdist;
int j,n3;
shortestPath()
{
infy=1000;
}
void input()
{
try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the no of nodes");
String n1=br.readLine();
n=Integer.parseInt(n1);
System.out.println("Enter the nodes");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
String n2=br.readLine();
n3=Integer.parseInt(n2);
weight[i][j]=n3;
}
}
System.out.println("Enter the source");
String s1=br.readLine();
s=Integer.parseInt(s1);
System.out.println("Enter the Destination");
String t1=br.readLine();
t=Integer.parseInt(t1);
}
catch(IOException e)
{
System.out.println("Error"+e);
}
spath(s,t);
}
void spath(int s,int t)
{
for(i=0;i<n;i++)
{
prem[i]=0;
distance[i]=infy;
}
distance[s]=0;
prem[s]=1;
current=s;
while(current!=t)
{
smalldist=infy;
dc=distance[current];
for(i=0;i<n;i++)
{
if(prem[i]==0)
{
newdist=dc+weight[current][i];
if(newdist<distance[i])
{
distance[i]=newdist;
}
if(distance[i]<smalldist)
{
smalldist=distance[i];
k=i;
}}}
current=k;
prem[current]=1;
}
pd=distance[t];
System.out.println("ShortestPath="+pd);
}
public static void main(String args[])throws IOException
{
shortestPath sp=new shortestPath();
sp.input();
}}
OUTPUT
1000
10
20
30
200
1000
1000
1000
50
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
60
1000
1000
70
1000
1000
ShortestPath=90
RESULT:
AIM:
ALGORITHM:
Client Side:
Server Side:
RARP CLIENT:
import java.io.*;
import java.net.*;
class rarpclient
{
public static void main(String args[])throws IOException
{
Socket s1=new Socket("localhost",3500);
DataInputStream in=new DataInputStream(s1.getInputStream());
DataOutputStream on=new DataOutputStream(s1.getOutputStream());
BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));
while(true)
{
System.out.println("Enter mac add");
String o=b.readLine() ;
on.writeUTF(o);
String t=in.readUTF();
System.out.println("The IP add"+t);
}
}
}
RARP SERVER:
import java.io.*;
import java.net.*;
class rarpserver
{
public static void main(String args[])throws IOException
{
ServerSocket s=new ServerSocket(3500);
Socket c=s.accept();
DataInputStream i=new DataInputStream(c.getInputStream());
DataOutputStream o=new DataOutputStream(c.getOutputStream());
BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));
String ip[]=new String[100];
String mac[]=new String[100];
System.out.println("How many add to be updated");
int n=Integer.parseInt(b.readLine());
int f=0,h=0;
for(int j=0;j<n;j++)
{
int u=j+1;
System.out.println("Enter the "+u+"ip address");
ip[j]=b.readLine();
System.out.println("Enter CORRES mac address");
mac[j]=b.readLine();
}
while(true)
{
f=0;
String t=i.readUTF();
System.out.println("Please send the ip add of"+t);
for(int k=0;k<n;k++)
{
if(mac[k].equals(t))
{
o.writeUTF(ip[k]);
f=1;
break;
}
}
if(f==0)
{o.writeUTF("add cannot be resolved");
}
}
}
}
OUTPUT:
C:\jdk1.3\bin>javac rarpserver.java
C:\jdk1.3\bin>java rarpserver
How many add to be updated
2
Enter the 1ip address
192.168.0.10
Enter CORRES mac address
10
Enter the 2ip address
192.168.0.23
Enter CORRES mac address
23
Please send the ip add of10
Please send the ip add of23
Please send the ip add of12
C:\jdk1.3\bin>javac rarpclient.java
C:\jdk1.3\bin>java rarpclient
Enter mac add
10
The IP add192.168.0.10
Enter mac add
23
The IP add192.168.0.23
Enter mac add
12
The IP addadd cannot be resolved
RESULT: