huuCONTENTS S.No . DATE NAME OF THE EXPERIMENT PAGE NO. REMARKS 1. Retrieving Data with URLs 2a. String Transfer between two applications - TCP 2b. String Transfer between two applications - UDP 3. File Transfer using - TCP 4a. Implementation of Echo 4b. Implementation of Ping 4c. Implementation of Talk 5. File Remote Command Execution 6. ARP – Address Resolution Protocol 7 RARP – Reverse Address Resolution Protocol 8. RMI Implementation for a given function. 9 Implementation of shortest path routing algorithm. 10 Implementation of sliding window protocol.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
huuCONTENTS
S.No. DATE NAME OF THE EXPERIMENTPAGE
NO.REMARKS
1. Retrieving Data with URLs
2a. String Transfer between two applications - TCP
2b. String Transfer between two applications - UDP
3. File Transfer using - TCP
4a. Implementation of Echo
4b. Implementation of Ping
4c. Implementation of Talk
5. File Remote Command Execution
6. ARP – Address Resolution Protocol
7 RARP – Reverse Address Resolution Protocol
8. RMI Implementation for a given function.
9 Implementation of shortest path routing algorithm.
public class url extends JFrame implements ActionListener{JTextField tf;
url(){JFrame f = new JFrame();JPanel p= new JPanel();JLabel l1=new JLabel("URL:");tf= new JTextField(10);JButton b = new JButton("click");p.add(l1);p.add(tf);p.add(b);b.addActionListener(this);f.getContentPane().add(p);f.pack();f.setVisible(true);}
public void actionPerformed(ActionEvent ae){BareBonesBrowserLaunch.openURL(tf.getText().trim());}
public static void main(String[] args){url s=new url();}
public class BareBonesBrowserLaunch{public static void openURL(String url){try{Runtime.getRuntime().exec("rundll32.url.dll,FileProtocolHanler "+url);}catch(Exception e){}}}
OUTPUT:
Source code:Client:import java.io.*;import java.net.*;import java.lang.*;public class ClientTCP{ public static void main(String args[])
{try{ InetAddress id=InetAddress.getLocalHost(); Socket s = new Socket(id,80); DataInputStream dis=new DataInputStream(System.in); DataInputStream sdis=new DataInputStream(s.getInputStream()); PrintStream ps=new PrintStream(s.getOutputStream()); boolean flag=false; do {
System.out.println("\n1.Send\n2.Receive\n3.Exit\n");System.out.println("Your Choice(123):");String c=dis.readLine();int ch=Integer.parseInt(c);switch(ch){ case 1:System.out.println("\nEnter the Message to send");String msg=dis.readLine();ps.println(msg.toString());break;case 2:int a=sdis.available();String msgs=sdis.readLine();if(a!=0){System.out.println("\nThe Message Received is");System.out.println(msgs);}elseSystem.out.println("The Message is not received");break;case 3:s.close();flag=true;}
}while(!flag);
}catch(Exception e){}
}}
ServerTCP:import java.io.*;import java.net.*;import java.lang.*;public class ServerTCP{ public static void main(String args[])
System.out.println("\n1.Send\n2.Receive\n3.Exit\n"); System.out.println("Your Choice(123):");String c=dis.readLine();int ch=Integer.parseInt(c);switch(ch){ case 1:System.out.println("\nEnter the Message to send");String msg=dis.readLine();ps.println(msg.toString());break;case 2:int a=sdis.available();String msgs=sdis.readLine();if(a!=0){System.out.println("\nThe Message Received is");System.out.println(msgs);}elseSystem.out.println("The Message is not received");
public class server {public static int serverport=998;public static int clientport=999;public static int buffersize=1024;public static byte buffer[]=new byte[buffersize];public static DatagramSocket ds;
public static void serve() throws Exception{
int pos=0;System.out.println(" I AM WAITING FOE YOUR INPUT");
while(true){
int c = System.in.read();switch(c){case 1:System.out.println("server");return;case '\r':break;case '\n':ds.send(new
try{echosocket = new Socket(InetAddress.getLocalHost(),1092);in= new BufferedReader(new InputStreamReader(echosocket.getInputStream()));}catch(UnknownHostException e){System.err.println("could not get io for the connection");System.exit(1);}String UserInput;while((UserInput=in.readLine())!=null){System.out.println(UserInput);}in.close();echosocket.close();}}
}catch(IOException e){System.err.println("could not listen on port 1092");System.exit(1);}Socket clientsock=null;try{clientsock=serversock.accept();System.out.println("connected to client sock");}catch(IOException e){System.err.println("accept failed");System.exit(1);}PrintWriter outprint=new PrintWriter(clientsock.getOutputStream(),true);String inputline,outputline;BufferedReader b=new BufferedReader(new InputStreamReader(System.in));System.out.println("enter the name of the file");String s=b.readLine();File f=new File(s);if(f.exists()){BufferedReader d=new BufferedReader(new FileReader(s));String line;while((line=d.readLine())!=null){outprint.write(line);outprint.flush();}d.close();}b.close();outprint.close();serversock.close();clientsock.close();}}
public class EchoClient{ public static void main(String args[]) {
String sockin;try{
Socket csok = new Socket(InetAddress.getLocalHost(),2000);BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));BufferedReader br_sock = new BufferedReader(new
InputStreamReader(csok.getInputStream()));PrintStream ps = new PrintStream(csok.getOutputStream());System.out.println("Start Echoing...Type 'end' to terminate");while((sockin = br.readLine())!=null){ps.println(sockin);if(sockin.equals("end"))break;elseSystem.out.println("Reflected from Server:"+br_sock.readLine());}
if(p==null)System.out.println("could not connect");in=new BufferedReader(new InputStreamReader(p.getInputStream()));String line;
while((line=in.readLine())!=null){
if(line.startsWith("reply"))System.out.println("this is reply");else if(line.startsWith("request"))System.out.println("there is no reply");else if(line.startsWith("destinator"))System.out.println("destinator host unreachabl");elseSystem.out.println(line);
n4.DIVISION\n5.QUIT");System.out.println("Enter your Choice(1,2,3,4,5):");int ch=Integer.parseInt(in.readLine());
switch(ch){case 1:
System.out.println("Enter two nos to ADD..");int a1=Integer.parseInt(in.readLine());int b1=Integer.parseInt(in.readLine());System.out.println("ADDITION RESULTS:"+(ref.add(a1,b1)));break;
case 2:System.out.println("Enter two nos to Subtract..");int a2=Integer.parseInt(in.readLine());int b2=Integer.parseInt(in.readLine());System.out.println("SUBTRACTION RESULTS:"+(ref.sub(a2,b2)));break;
case 3:System.out.println("Enter two nos to Mul..");int a3=Integer.parseInt(in.readLine());int b3=Integer.parseInt(in.readLine());System.out.println("MULTIPLICATION RESULTS:"+(ref.mul(a3,b3)));break;
case 4:System.out.println("Enter two nos to Div..");int a4=Integer.parseInt(in.readLine());int b4=Integer.parseInt(in.readLine());System.out.println("DIVISION RESULTS:"+(ref.div(a4,b4)));break;
case 5: flag=true;break;
}}while(!flag);}catch(Exception e){}}
}
Implementation Program (RMIImpl):import java.rmi.*;import java.rmi.server.UnicastRemoteObject;
public class RMIImpl extends UnicastRemoteObject implements RMIIntf{
public RMIImpl()throws RemoteException{}public int add(int a, int b)throws RemoteException{
return(a+b);}public int sub(int a, int b)throws RemoteException{
return(a-b);}public int mul(int a, int b)throws RemoteException{
return(a*b);}public int div(int a, int b)throws RemoteException{
return(a/b);}
}
RMI Server side Interface Program (RMIIntf):
import java.rmi.Remote;import java.rmi.*;
public interface RMIIntf extends Remote{
int add(int a, int b)throws RemoteException;int sub(int a, int b)throws RemoteException;int mul(int a, int b)throws RemoteException;int div(int a, int b)throws RemoteException;
}
RMI Server Program (RMIServer):import java.net.*;import java.rmi.Naming;
import java.io.*;class spr{public static void main(String args[]) throws Exception{int dist[][] = new int[50][50];int a[][] = new int[50][50];int path[][] = new int[50][50];int n, i, j, k, l; DataInputStream dis = new DataInputStream(System.in);String st;System.out.print("Enter the Number of vertices : ");st = dis.readLine();n = Integer.parseInt(st);System.out.println("Enter the Weight / Cost Between vertices, if no Enter 999");for(i=0; i<n; ++i)for(j=0; j<n; ++j) if( i !=j ) {
System.out.print(" From " + i + " To " + j + " : ");st = dis.readLine();dist[i][j] = Integer.parseInt(st);}elsedist[i][j] = 999;
} for(i=0; i<n; ++i) for(j=0; j<n; ++j)if( i != j ) if(path[i][j] == 0) {System.out.print("The Shortest path From " + i + " To"+j + " is ");System.out.println( i + " ===> " + j + " Cost is " + a[i][j] ); } else {
System.out.print("The Shortest path From " + i + " To"+ j+ " is ");System.out.print( i + " ===> " + path[i][j] + " ===> " + j); System.out.println(" Cost is " + a[i][j] ); } }}
Sliding Window Protocol
import java.io.*;
class p11sldwnd{int len; public static void main(String args[]) throws Exception{p11sldwnd pvar = new p11sldwnd();int a[] = new int[50];int b[] = new int[50];int n, wsz, i, j, k, t, v, ch, sdch, rvch; DataInputStream dis = new DataInputStream(System.in);String st;j = t = v = wsz = 0;while(true){System.out.println("\n\t\t\tSLIDING WINDOW PROTOCOL");System.out.println("\t\t\t*************************\n");
System.out.println("\t\t1. Sender");System.out.println("\t\t2. Receiver");System.out.println("\t\t3. Exit");System.out.print("\t\t Enter Your Choice : ");st = dis.readLine();ch = Integer.parseInt(st);switch(ch){case 1 : bk1: while(true){
System.out.println("\n\t\tData Senders Menu");System.out.println("\t\t-----------------");System.out.println("\t\t1. Store");System.out.println("\t\t2. Window Size Set");System.out.println("\t\t3. Transit");System.out.println("\t\t4. Curret Window Items");System.out.println("\t\t5. Exit");System.out.print("\t\t Enter Your Choice : ");st = dis.readLine();sdch = Integer.parseInt(st);switch(sdch){case 1:System.out.print("\n\t\t How many Data want to Store - n : ");st = dis.readLine();n = Integer.parseInt(st);for(i=0; i<n; ++i){System.out.print("\n\t\t Enter the data : ");
st = dis.readLine();a[i] = Integer.parseInt(st);}break;case 2:System.out.print("\n\t\t Enter the Window Size : ");st = dis.readLine();wsz = Integer.parseInt(st);break;case 3:System.out.print("\n\t\t How many data want to transmit : ");st = dis.readLine();pvar.len = Integer.parseInt(st);for(i=0; i < pvar.len; ++i)System.out.println(b[i]);break;case 4:System.out.println("\n\t\t The Data nside Transmitter Window");t = 0;wsz = wsz + j;v = v + j;for(i=v; i < wsz; ++i)b[t++] = a[i];for(i=0; i < t; ++i)System.out.println(b[i]);break;case 5:break bk1;}}break;case 2: bk2: while(true){System.out.println("\n\t\tData Receivers Menu");System.out.println("\t\t-------------------");System.out.println("\t\t1. Receive");System.out.println("\t\t2. Acknowledge");System.out.println("\t\t3. Exit");System.out.print("\t\t Enter Your Choice : ");st = dis.readLine();rvch = Integer.parseInt(st);switch(rvch){case 1:
System.out.println("\n\t\t The number of data Reveived ");for(i=0; i < pvar.len; ++i)System.out.println(b[i]);
break;case 2:System.out.print("\n\t\t Enter the number of data Acknowledged: ");
st = dis.readLine();j = Integer.parseInt(st);break;case 3:break bk2;}