Académique Documents
Professionnel Documents
Culture Documents
PAGE
S.No. DATE NAME OF THE EXPERIMENT REMARKS
NO.
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.
Implementation of shortest path routing
9
algorithm.
10 Implementation of sliding window protocol.
SOURCE CODE:
URL:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
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);
}
}
BareBonesBrowserLaunch:
import java.lang.reflect.Method;
import java.util.Arrays;
import javax.swing.JOptionPane;
ServerTCP:
import java.io.*;
import java.net.*;
import java.lang.*;
public class ServerTCP
{
public static void main(String args[])
{
try
{
ServerSocket ss=new ServerSocket(80);
Socket s = ss.accept();
OUTPUT:
SOURCE CODE:
SERVER:
package mynetapp;
import java.io.*;
import java.net.* ;
import java.lang.*;
while(true)
{
int c = System.in.read();
switch(c)
{
case 1:
System.out.println("server");
return;
case '\r':break;
case '\n':ds.send(new
DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientport));
pos=0;
break;
default:
buffer[pos++]=(byte)c;
break;
}
}
}
public static void main(String arg[])throws Exception
{
ds=new DatagramSocket();
serve();
}
}
CLIENT:
package mynetapp;
import java.net.*;
class client
{
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;
while(true)
{
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
ds.receive(p);
System.out.println(new String(p.getData(),0,p.getLength()));
}
}
}
OUTPUT:
D:\java\MEPRACTICE>java server
D:\java\MEPRACTICE>java client
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();
}
}
FSERVER:
import java.net.*;
import java.io.*;
class Fserver
{
public static void main(String args[])throws Exception
{
ServerSocket serversock=null;
try
{
try
{
ssock = new ServerSocket(2000);
csok = ssock.accept();
br = new BufferedReader(new InputStreamReader(csok.getInputStream()));
import java.io.*;
import java.net.*;
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");
else
System.out.println(line);
}
System.out.println(in.readLine());
in.close();
} catch(IOException e)
{System.out.println(e.toString());}
}
}
OUTPUT:
SOURCE CODE
TalkServer:
import java.io.*;
import java.net.*;
ServerSocket ssock;
Socket csok;
BufferedReader br_local,br_sock;
String sysin,sockin;
try
{
ssock = new ServerSocket(2000);
csok = ssock.accept();
br_local = new BufferedReader(new InputStreamReader(System.in));
br_sock = new BufferedReader(new
InputStreamReader(csok.getInputStream()));
PrintStream ps = new PrintStream(csok.getOutputStream());
System.out.println("Connected......start conversation...type end to terminate");
while((sockin = br_sock.readLine()) != null)
{
System.out.println(sockin);
if(sockin.equalsIgnoreCase("end"))
{
System.out.println("Client disconnected");
break;
}
sysin = br_local.readLine();
if(sysin.equalsIgnoreCase("end"))
{
System.out.println("Server says stop conversation");
break;
}
else
{ ps.println(sysin);}
}
}
catch(UnknownHostException uhe)
{ System.out.println(uhe.toString());}
catch(IOException ioe)
{ System.out.println(ioe);}
}
}
TalkClient:
import java.io.*;
import java.net.*;
class remoteserver
{
public static void main(String args[])throws Exception
{
String com=new String();
ServerSocket ss=new ServerSocket(100);
Socket s=ss.accept();
BufferedReader nin=new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter nout=new PrintWriter(s.getOutputStream(),true);
do
{
com=nin.readLine();
if(com.equalsIgnoreCase("date"))
{
Calendar c=Calendar.getInstance();
nout.println(c.get(Calendar.DAY_OF_MONTH)+","+
(c.get(Calendar.MONTH)+","+(c.get(Calendar.MONTH)
+1)+","+c.get(Calendar.YEAR)));
nout.println(c.get(Calendar.HOUR)+","+(c.get(Calendar.MINUTE)
+1)+","+c.get(Calendar.SECOND));
System.out.println("Time is sent.connection terminated with
client");
}
else
{
nout.println("your request is invalid");
System.out.println("Proper response is sent to your client");
}
}
}
while(!com.equalsIgnoreCase("bye"));
System.out.println("connection terminated with client");
}
}
REMOTECLIENT2:
import java.io.*;
import java.net.*;
class remoteclient2
{
public static void main(String args[])throws IOException
{
String rec=new String();
String res=new String();
try
{
Socket s=new Socket(InetAddress.getLocalHost(),100);
BufferedReader cin=new BufferedReader(new
InputStreamReader(System.in));
BufferedReader sin=new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter nout=new PrintWriter(s.getOutputStream(),true);
do
{
rec=cin.readLine();
nout.println(rec);
res=sin.readLine();
System.out.println(res);
}
while(rec.equalsIgnoreCase("bye"));
}
catch(Exception e)
{
System.out.println("error:"+e);
}
}
}
OUTPUT:
SOURCE CODE:
ARP:
import java.sql.*;
import java.io.*;
import java.net.*;
class arp
{
public static void main(String args[])throws IOException
{
try
{
Class.forName("sun.jdbc.odbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:jafer");
Statement s=cn.createStatement();
ResultSet rs=s.executeQuery("select * from address");
while(rs.next())
{
String log_add=rs.getString(1);
if(log_user.equals(log_add.trim()))
{
a=1;
phy_add=rs.getString(2);
}
}
if(a==1)
{
System.out.println();
System.out.println("The given logical address exists");
System.out.println("The physical address is :"+phy_add);
}
else
System.out.println("Your logical address does not exist");
}catch(Exception e){}
}
}
OUTPUT:
SOURCE CODE:
RARP:
import java.sql.*;
import java.io.*;
import java.net.*;
class rarp
{
public static void main(String args[])throws IOException
{
try
{
Class.forName("sun.jdbc.odbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:jafer");
Statement s=cn.createStatement();
ResultSet rs=s.executeQuery("select * from address");
while(rs.next())
{
String phy_add=rs.getString(2);
if(phy_user.equals(phy_add.trim()))
{
a=1;
log_add=rs.getString(1);
}
}
if(a==1)
{
System.out.println();
System.out.println("The given physical address exists");
System.out.println("The logical address is :"+log_add);
}
else
System.out.println("Your physical address does not exist");
}catch(Exception e){}
}
}
OUTPUT:
SOURCE CODE:
try
{
DataInputStream in = new DataInputStream(System.in);
RMIIntf ref=(RMIIntf)Naming.lookup("impl");
boolean flag=false;
do
{
System.out.println("1.ADDITION\n2.SUBTRACTION\n3.MULTIPLICATION\n4.DIVI
SION\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){}
}
}
import java.rmi.Remote;
import java.rmi.*;
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)
{