SlideShare a Scribd company logo
1 of 18
Download to read offline
Practical No:1(a)
Aim: Study of URL.
#Source Code:
import java.io.*;
import java.net.*;
public class GetURL
{
public static void main(String[] args)
{
InputStream in=null;
OutputStream out=null;
try
{
if((args.length!=1)&&(args.length!=2))
throw new IllegalArgumentException("Wrong number of args");
URL url=new URL(args[0]);
in=url.openStream();
if(args.length==2)
out=new FileOutputStream(args[1]);
else out=System.out;
byte[] buffer=new byte[4096];
int bytes_read;
while((bytes_read=in.read(buffer))!=-1)
out.write(buffer,0,bytes_read);
}
catch(Exception e)
{
System.err.println(e);
System.err.println("Usage.java GetURL<URL>[<filename>]");
}
finally
{
try{
in.close();
out.close();
}
catch(Exception e){}
}
}
}
****************************************************************
<html>
<head>
<title>YAhoo</title>
</head>
<body>
NOthing is impossible
</body>
</html>
****************************************************************
Output:
Practical No:1(b)
Aim: Study of URLInfo.
#Source Code:
import java.net.*;
import java.io.*;
import java.util.Date;
public class GetURLInfo
{
public static void printinfo(URL url) throws IOException
{
URLConnection c = url.openConnection();
c.connect();
System.out.println(" Content Type: " + c.getContentType());
System.out.println(" Content Encoding: " + c.getContentEncoding());
System.out.println(" Content Length: " + c.getContentLength());
System.out.println(" Date: " + new Date(c.getDate()));
System.out.println(" Last Modified: " +new
Date(c.getLastModified()));
System.out.println(" Expiration: " + new Date(c.getExpiration()));
if (c instanceof HttpURLConnection)
{
HttpURLConnection h = (HttpURLConnection) c;
System.out.println(" Request Method: " + h.getRequestMethod());
System.out.println(" Response Message: " +h.getResponseMessage());
System.out.println(" Response Code: " + h.getResponseCode());
}
}
public static void main(String[] args)
{
try
{
printinfo(new URL(args[0]));
}
catch (Exception e)
{
System.err.println(e);
System.err.println("Usage: java GetURLInfo<url>");
}
}
}
****************************************************************
Output:
Practical No:2(a)
Aim: Study of InetTest.
#Source Code:
import java.net.*;
class InetTest
{
public static void main(String[] args)
{
try
{
InetAddress i = InetAddress.getByName(args[0]);
System.out.println(i.getHostAddress());
}
catch(Exception e)
{
e.printStackTrace();
}
InetTest i = new InetTest();
}
}
****************************************************************
Output:
Practical No:2(b)
Aim: Study of InetTest1
#Source Code:
import java.net.*;
class InetTest1
{
public static void main(String [] args)
{
try
{
InetAddress i=InetAddress.getLocalHost();
System.out.println(i.getHostAddress());
}
catch(Exception e)
{
e.printStackTrace();
}
InetTest1 j1= new InetTest1();
}
}
****************************************************************
Output:
Practical No:2(c)
Aim: Study of InetAddressTest.
#Source Code:
import java.net.*;
class InetAddressTest
{
public static void main(String args[]) throws UnknownHostException {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
Address = InetAddress.getByName("youtube.com");
System.out.println(Address);
InetAddress SW[] = InetAddress.getAllByName("www.gmail.com");
for (int i=0; i<SW.length; i++)
System.out.println(SW[i]);
}
}
****************************************************************
Output:
Practical No:3
Aim: Program to demonstrate various part of URL.
#Source Code:
import java.net.*;
import java.io.*;
public class URLDemo1
{
public static void main(String [] args)
{
try
{
URL url = new URL(args[0]);
System.out.println("URL is " + url.toString());
System.out.println("protocol is " + url.getProtocol());
System.out.println("authority is " + url.getAuthority());
System.out.println("file name is " + url.getFile());
System.out.println("host is " + url.getHost());
System.out.println("path is " + url.getPath());
System.out.println("port is " + url.getPort());
System.out.println("default port is "+ url.getDefaultPort());
System.out.println("query is " + url.getQuery());
System.out.println("ref is " + url.getRef());
}catch(IOException e)
{
e.printStackTrace();
}
}
}
****************************************************************
Output:
Practical No:4
Aim: Connectionless Communication between server and client using
datagram.
#Source Code:
Server:
import java.io.*;
import java.net.*;
class UDPServer
{
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(9876);
//Server Socekt Created
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData,
receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
System.out.println("RECEIVED: " + sentence);
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
//Change sentence to Capital letter
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length,
IPAddress, port);
serverSocket.send(sendPacket);
//Send Capitalized data back to client
}
}
}
Client:
import java.io.*;
import java.net.*;
class UDPClient
{
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =new BufferedReader(new
InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
//Client Socket is created
InetAddress IPAddress = InetAddress.getByName("localhost");
//Gets the IP Address
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
//sends data
DatagramPacket sendPacket = new DatagramPacket(sendData,
sendData.length, IPAddress,9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket
(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence = new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
****************************************************************
Output:
Client:
Server:
Practical No:5
Aim: Socket Programming.
#Source Code:
Server:
import java.net.*;
import java.io.*;
class Server extends Thread
{
BufferedReader br;
Socket s1;
ServerSocket ss;
Server()
{
try
{
ss=new ServerSocket(7200);
s1=ss.accept();
InputStreamReader i = new InputStreamReader(s1.getInputStream());
br=new BufferedReader(i);
start();
System.out.println("Server");
ServerInner ci = new ServerInner();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void run()
{ try
{
while(true)
{
String s2=br.readLine();
System.out.println("Msg from Client: "+s2);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
Server c = new Server();
}
class ServerInner extends Thread
{
BufferedReader br1;
PrintWriter pw;
ServerInner()
{
try
{
InputStreamReader i = new InputStreamReader(System.in);
br=new BufferedReader(i);
pw = new PrintWriter(s1.getOutputStream(),true);
start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void run()
{
try
{
while(true)
{
String s=br.readLine();
pw.println(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
Client:
import java.net.*;
import java.io.*;
class Client extends Thread
{
BufferedReader br;
Socket s;
PrintWriter pw;
Client()
{
try
{
InputStreamReader i = new InputStreamReader(System.in);
br=new BufferedReader(i);
s=new Socket(InetAddress.getLocalHost(),7200);
pw = new PrintWriter(s.getOutputStream(),true);
start();
System.out.println("Client");
ClientInner ci = new ClientInner();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void run()
{ try
{
while(true)
{
String s=br.readLine();
pw.println(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
Client c = new Client();
}
class ClientInner extends Thread
{
BufferedReader br1;
ClientInner()
{ try
{
InputStreamReader i = new InputStreamReader(s.getInputStream());
br1=new BufferedReader(i);
start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void run()
{
try
{
while(true)
{
String s2=br1.readLine();
System.out.println("Msg from Server: "+s2);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
****************************************************************
Output:
Client:
Server:
DCN Practical

More Related Content

What's hot

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)mehul patel
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
 
Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
Smarter Testing with Spock
Smarter Testing with SpockSmarter Testing with Spock
Smarter Testing with SpockDmitry Voloshko
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestHoward Lewis Ship
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With SpockIT Weekend
 
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source CodeUsing Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source CodeNicolas Bettenburg
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2Technopark
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance PuzzlersDoug Hawkins
 

What's hot (19)

Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
Smarter Testing with Spock
Smarter Testing with SpockSmarter Testing with Spock
Smarter Testing with Spock
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
Java Language fundamental
Java Language fundamentalJava Language fundamental
Java Language fundamental
 
Unit Testing with Foq
Unit Testing with FoqUnit Testing with Foq
Unit Testing with Foq
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With Spock
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source CodeUsing Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
Using Fuzzy Code Search to Link Code Fragments in Discussions to Source Code
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Java practical
Java practicalJava practical
Java practical
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 

Similar to DCN Practical

201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programingwahyuseptiansyah
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdfJayaprasanna4
 
Java networking programs socket based
Java networking programs socket basedJava networking programs socket based
Java networking programs socket basedMukesh Tekwani
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 
Distributed systems
Distributed systemsDistributed systems
Distributed systemsSonali Parab
 
Java programs
Java programsJava programs
Java programsjojeph
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxhendriciraida
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harianKhairunnisaPekanbaru
 
Chapter 4 slides
Chapter 4 slidesChapter 4 slides
Chapter 4 slideslara_ays
 

Similar to DCN Practical (20)

JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdf
 
Java networking programs socket based
Java networking programs socket basedJava networking programs socket based
Java networking programs socket based
 
Lecture6
Lecture6Lecture6
Lecture6
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
Server1
Server1Server1
Server1
 
Distributed systems
Distributed systemsDistributed systems
Distributed systems
 
Java programs
Java programsJava programs
Java programs
 
Ipc
IpcIpc
Ipc
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docx
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian
 
Fia fabila
Fia fabilaFia fabila
Fia fabila
 
Chapter 4 slides
Chapter 4 slidesChapter 4 slides
Chapter 4 slides
 
java sockets
 java sockets java sockets
java sockets
 
Lab4
Lab4Lab4
Lab4
 

More from Niraj Bharambe

T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityT.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityNiraj Bharambe
 
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Niraj Bharambe
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceNiraj Bharambe
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaNiraj Bharambe
 
Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01Niraj Bharambe
 
Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01Niraj Bharambe
 
Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01Niraj Bharambe
 
Sixth sense technology
Sixth sense technologySixth sense technology
Sixth sense technologyNiraj Bharambe
 
Embedded System Practical manual (1)
Embedded System Practical manual (1)Embedded System Practical manual (1)
Embedded System Practical manual (1)Niraj Bharambe
 
Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.Niraj Bharambe
 

More from Niraj Bharambe (18)

Tybsc cs dbms2 notes
Tybsc cs dbms2 notesTybsc cs dbms2 notes
Tybsc cs dbms2 notes
 
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityT.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
 
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
Python Book/Notes For Python Book/Notes For S.Y.B.Sc. I.T.
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer science
 
Core java tutorial
Core java tutorialCore java tutorial
Core java tutorial
 
Java unit 4_cs_notes
Java unit 4_cs_notesJava unit 4_cs_notes
Java unit 4_cs_notes
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of java
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01Xml 150323102007-conversion-gate01
Xml 150323102007-conversion-gate01
 
Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01Htmlnotes 150323102005-conversion-gate01
Htmlnotes 150323102005-conversion-gate01
 
Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01Htmlcolorcodes 150323101937-conversion-gate01
Htmlcolorcodes 150323101937-conversion-gate01
 
Definition
DefinitionDefinition
Definition
 
Sixth sense technology
Sixth sense technologySixth sense technology
Sixth sense technology
 
collisiondetection
collisiondetectioncollisiondetection
collisiondetection
 
Html color codes
Html color codesHtml color codes
Html color codes
 
Embedded System Practical manual (1)
Embedded System Practical manual (1)Embedded System Practical manual (1)
Embedded System Practical manual (1)
 
Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.Data Warehousing Practical for T.Y.I.T.
Data Warehousing Practical for T.Y.I.T.
 
Forouzan appendix
Forouzan appendixForouzan appendix
Forouzan appendix
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 

DCN Practical

  • 1. Practical No:1(a) Aim: Study of URL. #Source Code: import java.io.*; import java.net.*; public class GetURL { public static void main(String[] args) { InputStream in=null; OutputStream out=null; try { if((args.length!=1)&&(args.length!=2)) throw new IllegalArgumentException("Wrong number of args"); URL url=new URL(args[0]); in=url.openStream(); if(args.length==2) out=new FileOutputStream(args[1]); else out=System.out; byte[] buffer=new byte[4096]; int bytes_read; while((bytes_read=in.read(buffer))!=-1) out.write(buffer,0,bytes_read); } catch(Exception e) { System.err.println(e); System.err.println("Usage.java GetURL<URL>[<filename>]"); } finally { try{ in.close(); out.close(); } catch(Exception e){}
  • 3. Practical No:1(b) Aim: Study of URLInfo. #Source Code: import java.net.*; import java.io.*; import java.util.Date; public class GetURLInfo { public static void printinfo(URL url) throws IOException { URLConnection c = url.openConnection(); c.connect(); System.out.println(" Content Type: " + c.getContentType()); System.out.println(" Content Encoding: " + c.getContentEncoding()); System.out.println(" Content Length: " + c.getContentLength()); System.out.println(" Date: " + new Date(c.getDate())); System.out.println(" Last Modified: " +new Date(c.getLastModified())); System.out.println(" Expiration: " + new Date(c.getExpiration())); if (c instanceof HttpURLConnection) { HttpURLConnection h = (HttpURLConnection) c; System.out.println(" Request Method: " + h.getRequestMethod()); System.out.println(" Response Message: " +h.getResponseMessage()); System.out.println(" Response Code: " + h.getResponseCode()); } } public static void main(String[] args) { try { printinfo(new URL(args[0])); } catch (Exception e)
  • 5. Practical No:2(a) Aim: Study of InetTest. #Source Code: import java.net.*; class InetTest { public static void main(String[] args) { try { InetAddress i = InetAddress.getByName(args[0]); System.out.println(i.getHostAddress()); } catch(Exception e) { e.printStackTrace(); } InetTest i = new InetTest(); } } **************************************************************** Output:
  • 6. Practical No:2(b) Aim: Study of InetTest1 #Source Code: import java.net.*; class InetTest1 { public static void main(String [] args) { try { InetAddress i=InetAddress.getLocalHost(); System.out.println(i.getHostAddress()); } catch(Exception e) { e.printStackTrace(); } InetTest1 j1= new InetTest1(); } } **************************************************************** Output:
  • 7. Practical No:2(c) Aim: Study of InetAddressTest. #Source Code: import java.net.*; class InetAddressTest { public static void main(String args[]) throws UnknownHostException { InetAddress Address = InetAddress.getLocalHost(); System.out.println(Address); Address = InetAddress.getByName("youtube.com"); System.out.println(Address); InetAddress SW[] = InetAddress.getAllByName("www.gmail.com"); for (int i=0; i<SW.length; i++) System.out.println(SW[i]); } } **************************************************************** Output:
  • 8. Practical No:3 Aim: Program to demonstrate various part of URL. #Source Code: import java.net.*; import java.io.*; public class URLDemo1 { public static void main(String [] args) { try { URL url = new URL(args[0]); System.out.println("URL is " + url.toString()); System.out.println("protocol is " + url.getProtocol()); System.out.println("authority is " + url.getAuthority()); System.out.println("file name is " + url.getFile()); System.out.println("host is " + url.getHost()); System.out.println("path is " + url.getPath()); System.out.println("port is " + url.getPort()); System.out.println("default port is "+ url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); }catch(IOException e) { e.printStackTrace(); } } }
  • 10. Practical No:4 Aim: Connectionless Communication between server and client using datagram. #Source Code: Server: import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); //Server Socekt Created byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); String sentence = new String(receivePacket.getData()); System.out.println("RECEIVED: " + sentence); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); //Change sentence to Capital letter sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); //Send Capitalized data back to client } } }
  • 11. Client: import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser =new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); //Client Socket is created InetAddress IPAddress = InetAddress.getByName("localhost"); //Gets the IP Address byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); //sends data DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress,9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket (receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); }
  • 13. Practical No:5 Aim: Socket Programming. #Source Code: Server: import java.net.*; import java.io.*; class Server extends Thread { BufferedReader br; Socket s1; ServerSocket ss; Server() { try { ss=new ServerSocket(7200); s1=ss.accept(); InputStreamReader i = new InputStreamReader(s1.getInputStream()); br=new BufferedReader(i); start(); System.out.println("Server"); ServerInner ci = new ServerInner(); } catch(Exception e) { e.printStackTrace(); } } public void run() { try { while(true) { String s2=br.readLine(); System.out.println("Msg from Client: "+s2); } } catch(Exception e)
  • 14. { e.printStackTrace(); } } public static void main(String[] args) { Server c = new Server(); } class ServerInner extends Thread { BufferedReader br1; PrintWriter pw; ServerInner() { try { InputStreamReader i = new InputStreamReader(System.in); br=new BufferedReader(i); pw = new PrintWriter(s1.getOutputStream(),true); start(); } catch(Exception e) { e.printStackTrace(); } } public void run() { try { while(true) { String s=br.readLine(); pw.println(s); } } catch(Exception e) { e.printStackTrace(); }
  • 15. } } } Client: import java.net.*; import java.io.*; class Client extends Thread { BufferedReader br; Socket s; PrintWriter pw; Client() { try { InputStreamReader i = new InputStreamReader(System.in); br=new BufferedReader(i); s=new Socket(InetAddress.getLocalHost(),7200); pw = new PrintWriter(s.getOutputStream(),true); start(); System.out.println("Client"); ClientInner ci = new ClientInner(); } catch(Exception e) { e.printStackTrace(); } } public void run() { try { while(true) { String s=br.readLine(); pw.println(s); } } catch(Exception e) {
  • 16. e.printStackTrace(); } } public static void main(String[] args) { Client c = new Client(); } class ClientInner extends Thread { BufferedReader br1; ClientInner() { try { InputStreamReader i = new InputStreamReader(s.getInputStream()); br1=new BufferedReader(i); start(); } catch(Exception e) { e.printStackTrace(); } } public void run() { try { while(true) { String s2=br1.readLine(); System.out.println("Msg from Server: "+s2); } } catch(Exception e) { e.printStackTrace(); } }