You are on page 1of 8

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY

BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

1.Aim:- Write an application to retrieve IP address of any website. Code:import java.net.*; import java.io.*; class IP { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter Website Name : "); InetAddress ip = InetAddress.getByName(br.readLine());

System.out.println(ip); } }

Output:-

2.Aim:- Write an application to find an IP address of the machine on which the program runs or own system. Code:import java.net.InetAddress; public class IP_local { public static void main(String[] args) {

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

try { InetAddress ip=InetAddress.getLocalHost(); System.out.println("IP is : "+ip.getHostAddress()); } catch (Exception e) { System.out.println(e); } } }

Output:-

3.Aim:- Write an application to demonstrate network application to convert given string in Lower case. Code:From server side:import java.io.*; import java.net.*;

class server { public static void main(String args[]) throws Exception { ServerSocket ss = new ServerSocket(62); Socket s = ss.accept();

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

OutputStream obj = s.getOutputStream(); PrintStream ps = new PrintStream(obj);

BufferedReader sr = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedReader kr = new BufferedReader(new InputStreamReader(System.in)); String str1,lc; while(true) { str1 = sr.readLine(); System.out.println("Request received to Convert \""+str1+"\" to lowercase:\n"); System.out.println("Converting \""+str1+"\" to lowercase..."); lc =str1.toLowerCase(); ps.println(lc); } } }

From client side:import java.io.*; import java.net.*; class client { public static void main(String args[]) throws Exception { Socket s = new Socket("localhost",62);

OutputStream obj = s.getOutputStream();

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

PrintStream ps = new PrintStream(obj); BufferedReader sr = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedReader kr = new BufferedReader(new InputStreamReader(System.in)); String str1,str2; while(!(str1=kr.readLine()).equals("exit")) { ps.println(str1); str2 = sr.readLine(); System.out.println("\nLowercase : \""+str2+"\""); } } }

Output:-

4.Aim:- Write an application to demonstrate network application to find the area of circle
using TCP.

Code:From server side:import java.net.*; import java.io.*; public class server { public static void main(String args[]) throws Exception {

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

ServerSocket ss=new ServerSocket(62); Socket s=ss.accept(); BufferedReader br= new BufferedReader(new double rad,area; String result; rad=Double.parseDouble(br.readLine()); System.out.println("From Client : "+rad); area=Math.PI*rad*rad; result="Area is "+area; PrintStream ps=new PrintStream(s.getOutputStream()); ps.println(result); br.close(); ps.close(); s.close(); ss.close(); } } From client side:import java.net.*; import java.io.*; public class server { public static void main(String args[]) throws Exception { ServerSocket ss=new ServerSocket(62); Socket s=ss.accept(); InputStreamReader(s.getInputStream()));

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

BufferedReader br= new BufferedReader(new InputStreamReader(s.getInputStream())); double rad,area; String result; rad=Double.parseDouble(br.readLine()); System.out.println("From Client : "+rad); area=Math.PI*rad*rad; result="Area is "+area; PrintStream ps=new PrintStream(s.getOutputStream()); ps.println(result); br.close(); ps.close(); s.close(); ss.close(); } }

Output:-

5.Aim:- Write an application to demonstrate simple chat messenger using TCP. Code:Server side
import java.io.*; import java.net.*; class server {

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

public static void main(String args[]) throws Exception { ServerSocket ss = new ServerSocket(62); Socket s = ss.accept(); OutputStream obj = s.getOutputStream(); PrintStream ps = new PrintStream(obj); BufferedReader sr = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedReader kr = new BufferedReader(new InputStreamReader(System.in)); String str1,str2; while(true) { str1 = sr.readLine(); System.out.println(str1); str2 = kr.readLine(); ps.println(str2); } } }

Client side
import java.io.*; import java.net.*; class client { public static void main(String args[]) throws Exception { Socket s = new Socket("localhost",62);

100750116062

PRACTICAL-3

SHANKERSINH VAGHELA BAPU INSTITUTE OF TECHNOLOGY


BRANCH: -INFORMATION TECHNOLOGY SUBJECT: - ADVANCE JAVA

OutputStream obj = s.getOutputStream(); PrintStream ps = new PrintStream(obj);

BufferedReader sr = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedReader kr = new BufferedReader(new InputStreamReader(System.in)); String str1,str2; while(!(str1=kr.readLine()).equals("exit")) { ps.println(str1); str2 = sr.readLine(); System.out.println(str2); } } }

Output:-

100750116062

PRACTICAL-3