SlideShare a Scribd company logo
1 of 16
Java Networking
Java Networking
 Java Networking is a concept of connecting two
or more computing devices together so that we
can share resources.
 Java socket programming provides facility to
share data between different computing devices.
Advantage of Java Networking
 sharing resources
 centralize software management
Java Networking Terminology
The widely used java networking terminologies are given below:
 IP Address
 Protocol
 Port Number
 MAC Address
 Connection-oriented and connection-less protocol
 Socket
1) IP Address
IP address is a unique number assigned to a node of a network
e.g. 192.168.0.1 . It is composed of octets that range from 0 to
255.
It is a logical address that can be changed.
2) Protocol
A protocol is a set of rules basically that is followed for
communication. For example:
TCP
FTP
Telnet
SMTP
POP etc.
3) Port Number
The port number is used to uniquely identify different
applications. It acts as a communication endpoint between
applications.
The port number is associated with the IP address for
communication between two applications.
4) MAC Address
MAC (Media Access Control) Address is a unique identifier
of NIC (Network Interface Controller). A network node
can have multiple NIC but each with unique MAC.
5) Connection-oriented and connection-less protocol
In connection-oriented protocol, acknowledgement is sent
by the receiver. So it is reliable but slow. The example of
connection-oriented protocol is TCP.
But, in connection-less protocol, acknowledgement is not
sent by the receiver. So it is not reliable but fast. The
example of connection-less protocol is UDP.
6) Socket
A socket is an endpoint between two way communication.
Visit next page for java socket programming.
import java.net.*;
class Demo
{
public static void main(String[] args) throws
UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
address = InetAddress.getByName("www.facebook.com");
System.out.println(address);
InetAddress sw[] =
InetAddress.getAllByName("www.google.com");
for(int i=0; i< sw.length; i++)
{
System.out.println(sw[i]);
} } }
URL class
 Java URL Class present in java.net package,
deals with URL (Uniform Resource Locator)
which uniquely identify or locate resources on
internet.
Important Methods of URL class
 getProtocol() : Returns protocol of URL
 getHost() : Returns hostname(domain name) of
URL
 getPort() : Returns port number of URL
 getFile() : Returns filename of URL
import java.net.*;
class Demo
{
public static void main(String[] arg) throws
MalformedURLException
{
URL hp = new URL("http://www.kongu.ac.in/");
System.out.println(hp.getProtocol());
System.out.println(hp.getFile());
}
}
Socket class
 A socket is simply an endpoint for
communications between the machines. The
Socket class can be used to create a socket.
1) public InputStream getInputStream()returns the
InputStream attached with this socket.
2) public OutputStream getOutputStream()returns
the OutputStream attached with this socket.
3) public synchronized void close()closes this
socket
ServerSocket class
The ServerSocket class can be used to create a
server socket. This object is used to establish
communication with the clients.
 public Socket accept()returns the socket and
establish a connection between server and client.
 public synchronized void close()closes the server
socket.
URLConnection
 The Java URLConnection class represents a
communication link between the URL and the
application. This class can be used to read and
write data to the specified resource referred by
the URL.
The openConnection() method of URL class returns
the object of URLConnection class. Syntax:
public URLConnection openConnection()throws
IOException{}
DatagramSocket
 Java DatagramSocket class represents a
connection-less socket for sending and receiving
datagram packets.
 A datagram is basically an information but there is
no guarantee of its content, arrival or arrival time.
Constructors of DatagramSocket
class
 DatagramSocket() throws SocketEeption: it
creates a datagram socket and binds it with the
available Port Number on the localhost machine.
 DatagramSocket(int port) throws
SocketEeption: it creates a datagram socket and
binds it with the given Port Number.
 DatagramSocket(int port, InetAddress
address) throws SocketEeption: it creates a
datagram socket and binds it with the specified
port number and host address.
DatagramPacket
Java DatagramPacket is a message that can be
sent or received. If you send multiple packet, it
may arrive in any order. Additionally, packet
delivery is not guaranteed.
Constructors of DatagramPacket class
 DatagramPacket(byte[] barr, int length): it
creates a datagram packet. This constructor is
used to receive the packets.
 DatagramPacket(byte[] barr, int length,
InetAddress address, int port): it creates a
datagram packet. This constructor is used to send
the packets.
Java.net.URI class in Java
URI stands for Uniform Resource Identifier.
• A Uniform Resource Identifier is a sequence of
characters used for identification of a particular
resource.
• It enables for the interaction of the representation
of the resource over the network using specific
protocols.
URI, URL and URN
 A URI can be further classified as a locator, a
name, or both.
 The term “Uniform Resource Locator” (URL)
refers to the subset of URI that identify resources
via a representation of their primary access
mechanism (e.g., their network “location”), rather
than identifying the resource by name or by some
other attribute(s) of that resource.
 The term “Uniform Resource Name” (URN) refers
to the subset of URI that are required to remain
globally unique and persistent even when the
resource ceases to exist or becomes
unavailable.”

More Related Content

What's hot (20)

Java Programming - 07 java networking
Java Programming - 07 java networkingJava Programming - 07 java networking
Java Programming - 07 java networking
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
java networking
 java networking java networking
java networking
 
What is Socket Programming in Python | Edureka
What is Socket Programming in Python | EdurekaWhat is Socket Programming in Python | Edureka
What is Socket Programming in Python | Edureka
 
Networking in java
Networking in javaNetworking in java
Networking in java
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Python network programming
Python   network programmingPython   network programming
Python network programming
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Module 1 networking basics-2
Module 1   networking basics-2Module 1   networking basics-2
Module 1 networking basics-2
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
 
Python Sockets
Python SocketsPython Sockets
Python Sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Python networking
Python networkingPython networking
Python networking
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket Tutorial
 
Chapter 2.1 : Data Stream
Chapter 2.1 : Data StreamChapter 2.1 : Data Stream
Chapter 2.1 : Data Stream
 
Networking
NetworkingNetworking
Networking
 

Similar to Java networking

Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Javasuraj pandey
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13Sasi Kala
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Networking
NetworkingNetworking
NetworkingTuan Ngo
 
CHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxCHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxDhrumilSheth3
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.comphanleson
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
 
Java Network Programming 1197644949195966 4
Java Network Programming 1197644949195966 4Java Network Programming 1197644949195966 4
Java Network Programming 1197644949195966 4chendi.bhargavi
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In JavaAnkur Agrawal
 

Similar to Java networking (20)

Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Java
JavaJava
Java
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13
 
A.java
A.javaA.java
A.java
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Networking
NetworkingNetworking
Networking
 
CHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxCHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptx
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture25
Lecture25Lecture25
Lecture25
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 
Java seminar.pptx
Java seminar.pptxJava seminar.pptx
Java seminar.pptx
 
28 networking
28  networking28  networking
28 networking
 
Java Network Programming 1197644949195966 4
Java Network Programming 1197644949195966 4Java Network Programming 1197644949195966 4
Java Network Programming 1197644949195966 4
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In Java
 

More from ssuser3a47cb

Uunit 5-xml&web security
Uunit 5-xml&web securityUunit 5-xml&web security
Uunit 5-xml&web securityssuser3a47cb
 
Unit 4-SOA governance
Unit 4-SOA governanceUnit 4-SOA governance
Unit 4-SOA governancessuser3a47cb
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologiesssuser3a47cb
 
Unit 2 -SOA design
Unit 2 -SOA designUnit 2 -SOA design
Unit 2 -SOA designssuser3a47cb
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051ssuser3a47cb
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051ssuser3a47cb
 

More from ssuser3a47cb (10)

BCT.pptx
BCT.pptxBCT.pptx
BCT.pptx
 
Uunit 5-xml&web security
Uunit 5-xml&web securityUunit 5-xml&web security
Uunit 5-xml&web security
 
Unit 4-SOA governance
Unit 4-SOA governanceUnit 4-SOA governance
Unit 4-SOA governance
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologies
 
Unit 2 -SOA design
Unit 2 -SOA designUnit 2 -SOA design
Unit 2 -SOA design
 
Soa 1 7.ppsx
Soa 1 7.ppsxSoa 1 7.ppsx
Soa 1 7.ppsx
 
Java swing
Java swingJava swing
Java swing
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 

Java networking

  • 2. Java Networking  Java Networking is a concept of connecting two or more computing devices together so that we can share resources.  Java socket programming provides facility to share data between different computing devices.
  • 3. Advantage of Java Networking  sharing resources  centralize software management Java Networking Terminology The widely used java networking terminologies are given below:  IP Address  Protocol  Port Number  MAC Address  Connection-oriented and connection-less protocol  Socket
  • 4. 1) IP Address IP address is a unique number assigned to a node of a network e.g. 192.168.0.1 . It is composed of octets that range from 0 to 255. It is a logical address that can be changed. 2) Protocol A protocol is a set of rules basically that is followed for communication. For example: TCP FTP Telnet SMTP POP etc. 3) Port Number The port number is used to uniquely identify different applications. It acts as a communication endpoint between applications. The port number is associated with the IP address for communication between two applications.
  • 5. 4) MAC Address MAC (Media Access Control) Address is a unique identifier of NIC (Network Interface Controller). A network node can have multiple NIC but each with unique MAC. 5) Connection-oriented and connection-less protocol In connection-oriented protocol, acknowledgement is sent by the receiver. So it is reliable but slow. The example of connection-oriented protocol is TCP. But, in connection-less protocol, acknowledgement is not sent by the receiver. So it is not reliable but fast. The example of connection-less protocol is UDP. 6) Socket A socket is an endpoint between two way communication. Visit next page for java socket programming.
  • 6. import java.net.*; class Demo { public static void main(String[] args) throws UnknownHostException { InetAddress address = InetAddress.getLocalHost(); System.out.println(address); address = InetAddress.getByName("www.facebook.com"); System.out.println(address); InetAddress sw[] = InetAddress.getAllByName("www.google.com"); for(int i=0; i< sw.length; i++) { System.out.println(sw[i]); } } }
  • 7. URL class  Java URL Class present in java.net package, deals with URL (Uniform Resource Locator) which uniquely identify or locate resources on internet. Important Methods of URL class  getProtocol() : Returns protocol of URL  getHost() : Returns hostname(domain name) of URL  getPort() : Returns port number of URL  getFile() : Returns filename of URL
  • 8. import java.net.*; class Demo { public static void main(String[] arg) throws MalformedURLException { URL hp = new URL("http://www.kongu.ac.in/"); System.out.println(hp.getProtocol()); System.out.println(hp.getFile()); } }
  • 9. Socket class  A socket is simply an endpoint for communications between the machines. The Socket class can be used to create a socket. 1) public InputStream getInputStream()returns the InputStream attached with this socket. 2) public OutputStream getOutputStream()returns the OutputStream attached with this socket. 3) public synchronized void close()closes this socket
  • 10. ServerSocket class The ServerSocket class can be used to create a server socket. This object is used to establish communication with the clients.  public Socket accept()returns the socket and establish a connection between server and client.  public synchronized void close()closes the server socket.
  • 11. URLConnection  The Java URLConnection class represents a communication link between the URL and the application. This class can be used to read and write data to the specified resource referred by the URL. The openConnection() method of URL class returns the object of URLConnection class. Syntax: public URLConnection openConnection()throws IOException{}
  • 12. DatagramSocket  Java DatagramSocket class represents a connection-less socket for sending and receiving datagram packets.  A datagram is basically an information but there is no guarantee of its content, arrival or arrival time.
  • 13. Constructors of DatagramSocket class  DatagramSocket() throws SocketEeption: it creates a datagram socket and binds it with the available Port Number on the localhost machine.  DatagramSocket(int port) throws SocketEeption: it creates a datagram socket and binds it with the given Port Number.  DatagramSocket(int port, InetAddress address) throws SocketEeption: it creates a datagram socket and binds it with the specified port number and host address.
  • 14. DatagramPacket Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may arrive in any order. Additionally, packet delivery is not guaranteed. Constructors of DatagramPacket class  DatagramPacket(byte[] barr, int length): it creates a datagram packet. This constructor is used to receive the packets.  DatagramPacket(byte[] barr, int length, InetAddress address, int port): it creates a datagram packet. This constructor is used to send the packets.
  • 15. Java.net.URI class in Java URI stands for Uniform Resource Identifier. • A Uniform Resource Identifier is a sequence of characters used for identification of a particular resource. • It enables for the interaction of the representation of the resource over the network using specific protocols.
  • 16. URI, URL and URN  A URI can be further classified as a locator, a name, or both.  The term “Uniform Resource Locator” (URL) refers to the subset of URI that identify resources via a representation of their primary access mechanism (e.g., their network “location”), rather than identifying the resource by name or by some other attribute(s) of that resource.  The term “Uniform Resource Name” (URN) refers to the subset of URI that are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable.”