Está en la página 1de 5

ExNo:12b DOWNLOADING WEBPAGE DATA FROM HTTP

16.9.08 SERVER

AIM:
To download the particular content of file from the hypertext transfer protocol server
by using java program

DESIGN APPROACH:
A Server is a program running on remote machine providing service to client.A Server
program is an infinite program.It waits for incoming request from client.When a request
arrives,it responds to request.The http server consist of data related to websites alone.The
client will send http request to client server.The server will process the request and send
reply to client .All request based on websites.

ALGORITHM:
1. Include the java packages such as net,URL,etc..
2. Declare the URL values and assign a domain name to URL.
3. using socket read the URL by openStream function in BufferedReader
4. if the file is not null,then print the Content_Type, Content_encoding,up Date
date,installed date,length.
5. Display the download content of the particular website from the server.

PROGRAM:

import java.net.*;
import java.io.*;
import java.util.*;
public class mimehv
{
public static void main(String args[])
{
for(int i=0;i<args.length;i++)
{
try
{
URL u=new URL(args[i]);
URLConnection uc=u.openConnection();
System.out.println("content_type:"+uc.getContentType());
System.out.println("Content_encoding:"+uc.getContentEncoding());
System.out.println("Date:"+new Date(uc.getDate()));
System.out.println("LastModified:"+new Date(uc.getLastModified()));
System.out.println("ExpirationDate:"+new Date(uc.getExpiration()));
System.out.println("Content_length:"+uc.getContentLength());
}
catch(MalformedURLException e)
{
System.err.println(args[i]+"is not a URL I understand");
}
catch(IOException e)
{
System.err.println(e);
}
System.err.println();
}
}
}

RESULT:
Thus the particular content of file is downloaded from HTTP server.
ExNo:13 IMPLEMENTATION OF DOMAIN NAME SYSTEM
16.9.08

AIM:

To write a java program to implement the DNS to find the IP address of website.

DESIGN APPROACH:

DNS is protocol that can be used in different platform.In the internet,the DNS is
divided into three sections,Generic section,Country section,inverse section.The client will
send the request to server,the website address will reach the DNS.The DNS will give
the IP address of particular website.IP address will send to server.server send reply to
client.

ALGORITHM:

1. Declare some input address and website address.


2. Create an object for ServerSocket
3. Create an object for Socket and buffered reader to get the input.
4. Get the website name in the client port.
5. Read that in string str.
6. In server side check whether website is preseht or not.
7. If it is present then print IP address of that corresponding website address.
8. Then print DNS is resolved.
9. Else print Invalid IP address.

PROGRAM:

SERVER PROGRAM:

import java.io.*;
import java.net.*;
class dns_server
{
static final int port=8080;
static final String ipaddr[]={"192.168.5.3","192.168.32.06","225.326.148.7"};
static final String name[]={"www.yahoo.com","www.hotmail.com","www.google.com"};
public static void main(String args[])
{
try
{
ServerSocket ss=new ServerSocket(port);
System.out.println("\n serversocket:"+ss);
Socket s=ss.accept();
System.out.println("\n connection accepted socket:"+s);
BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
String host=in .readLine();
String comment="cannot be resolved";
int i=0;
while(i<3)
{
if(name[i].equals(host))
break;
i++;
}
PrintWriter out=new PrintWriter(new BufferedWriter(new
OutputStreamWriter(s.getOutputStream())),true);
if(i==3)
out.println(comment);
else
out.println(ipaddr[i]);
System.out.println("\n closing");
s.close();
}
catch(Exception e)
{
}
}
}

CLIENT PROGRAM:

import java.io.*;
import java.net.*;
class dns_client
{
static final int port=8080;
public static void main(String args[])
{
try
{
InetAddress addr=InetAddress.getByName("localhost");
Socket s=new Socket(addr,port);
System.out.println("enter the name of host:");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String name=in .readLine();
PrintWriter out=new PrintWriter(new BufferedWriter(new
OutputStreamWriter(s.getOutputStream())),true);
out.println(name);
BufferedReader brr=new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println("the IP address of host:"+brr.readLine());
}
catch(Exception e)
{
}
}
}

RESULT:
Thus DNS protocol to find the IP address of the website was implemented.

También podría gustarte