SlideShare a Scribd company logo
By – Gaurav
GOFORELEARNING@GMAIL.COM
Go GrEEN !
SaveEnvironment!
There are 3 requirements to establish a network:
 Hardware: includes the computers, cables, modems,
hubs, etc
 Software: includes program to communicate between
server and clients
 Protocols: represent a way to establish connection
and helps in sending and receiving data in a standard
format.
By – Gaurav
GOFORELEARNING@GMAIL.COM
 TCP/IP is a standard protocol model used on any
network.
 TCP/IP model has got the following 5 layers:
1. Application layer
2. TCP
3. IP
4. Data link layer
5. Physical layer
By – Gaurav
GOFORELEARNING@GMAIL.COM
1. Application layer
◦ Application layer is the topmost layer.
◦ This layer receives data from the application and formats the
data.
◦ it sends that data to the next layer called TCP in the form of
continuous stream of bytes.
2. TCP
◦ Receives data from Application layer,
◦ TCP will divide it into small segments called ‘packets’. A
packet contains a group of bytes of data.
◦ These packets are then sent to next IP layer
By – Gaurav
GOFORELEARNING@GMAIL.COM
3. IP layer
◦ IP layer inserts the packets into envelopes called
‘frames’.
◦ Each frame contains a packet:
 IP address of destination computer,
 IP address of source computer,
 some additional bits useful in error detection and
correction.
◦ These frames are then sent to Data link layer
By – Gaurav
GOFORELEARNING@GMAIL.COM
4. Data Link Layer
◦ Receives frames from the IP Layer.
◦ Dispatches them to correct destination computer
on the network.
5. Physical Layer
◦ This layer is used to physically transmit data on
the network using the appropriate hardware.
By – Gaurav
GOFORELEARNING@GMAIL.COM
 TCP/IP takes care of number of bits sent and weather
all the bits are received duly by the destination
computer. so it is called ‘connection oriented reliable
protocol’.
 This protocol is highly suitable for transporting data
reliably on a network.
 Almost all the protocol on Internet uses TCP/IP
model internally.
By – Gaurav
GOFORELEARNING@GMAIL.COM
IP Address:
 An IP address is a Unique Identification number given
to every computer on the network.
 It contain four integer numbers in the range of 0 to
255 and separated by a dot as 209.191.88.254
DNS (domain naming service)
 DNS is the mapping of IP addresses to human
readable names.
FTP (file transfer protocol)
 Useful to download or upload files from and to the
server.
By – Gaurav
GOFORELEARNING@GMAIL.COM
HTTP(Hypertext transfer protocol)
 Most widely used protocol on Internet, which is used
to transfer web pages (.html) from one computer to
anoher computer on Internet.
SMTP (simple mail transfer protocol)
 Useful to send mails on network.
POP(post office protocol)
 Useful to receive mails into the mailboxes.
By – Gaurav
GOFORELEARNING@GMAIL.COM
 Protocol that transfer data in a connection less and
unreliable manner.
 It will not check how many bits are sent or received at
the other side during transmission of data.
 UDP is used to send images, audio files and video files.
 Sockets provide the communication mechanism
between two computers using TCP.
 A client program creates a socket on its end of the
communication and attempts to connect that socket to
a server.
 When the connection is made, the server creates a
socket object on its end of the communication.
By – Gaurav
GOFORELEARNING@GMAIL.COM
 The client in socket programming must know two
information:
◦ IP Address of Server, and
◦ Port number.
 We should use a new port number for each new
socket.
 A socket, at server side is called ‘server socket’ and
is created using ServerSocket class in Java.
 A socket, at client side is called ‘socket’ and is
created using Socket class in Java.
By – Gaurav
GOFORELEARNING@GMAIL.COM
 getByName() method of InetAddress class of java.net
package.
By – Gaurav
GOFORELEARNING@GMAIL.COM
getByName()
Host Name / Server
Name
InetAddress/
IP Address
 URL URL(Uniform Resource Locator) represents the
address that is specified to access some information or
resources on world wide web.
 http://www.goforelearning.com:80/index.html
 The URL contains 4 parts
◦ The protocol to use (http://).
◦ The server name or IP address of the server(www.goforelearning.com)
◦ The third part represents ports number, which is optional (:80)
◦ The last part is the file name or directory name that is referred
(index.html).
 URL is represented by a class ‘URL’ in java.net package.
URL obj = new URL(String protocol, String host, int port,
String path);
By – Gaurav
GOFORELEARNING@GMAIL.COM
URLConnection Class is useful to actually connect
to a website or resource on a network and get all
the details of the website.
For example,
 To know the details of www.yahoo.com
◦ We should pass the URL to the object of URL class.
◦ Then using openConnection() method, we should
establish a contact with the site on Internet.
◦ This method return URLConnection object.
◦ Then using URLConnection class method, we can
display all the details of the website and also content
of the webpage whose name is given in URL.
By – Gaurav
GOFORELEARNING@GMAIL.COM
By – Gaurav
GOFORELEARNING@GMAIL.COM
Server
Server
Socket
OutputStreamPrintStream
ServerSocket ss = new ServerSocket (8080);
Socket s = ss.accept();
OutputStream obj = s.getOutputStream();
PrintStream ps = new PrintStream (obj);
ps.println(str);
ss.close();
s.close()
ps.close
By – Gaurav
GOFORELEARNING@GMAIL.COM
Socket
BufferedReaderInputStream
Socket s = new Socket (“IPAddress” , port number) ;
InputStream obj = s.get InputStream();
BufferedReader br = new BufferedReader (new InputStreamReader(obj));
Str = br.readLine();
br.close();
s.close()
Client
In case you don’t have your computer in a network, you have to run
both the server and client programs in the same system. In that case,
you can use localhost in place of IPAddress. The work localhost
represents that the server is also locally available in the same system.
We need additional streams both at server and client.
 InputStream obj = s.getInputStream();
 BufferedReader br = new BufferedReader (new
InputStreamReader(obj));
 OutputStream obj = s. getOutputStream();
 DataOutputStream dos = new DataOutputStream(obj);
writeBytes() method of DataOutputStream can be used to
send strings in form of groups of bytes.
Thank You !
Go GrEEN !
Save Environment!
For Any Queries: GOFORELEARNING@GMAIL.COM

More Related Content

What's hot

Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
suraj pandey
 
Simple chat room using python
Simple chat room using pythonSimple chat room using python
Simple chat room using python
VISHAL VERMA
 
Python Sockets
Python SocketsPython Sockets
Python Sockets
pythontic
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
Mohammed Abdalla Youssif
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
Yuvaraja Ravi
 
retrieving the mail
retrieving the mailretrieving the mail
retrieving the mail
tumetr1
 
2014 07-14 t14-50-08-netlog
2014 07-14 t14-50-08-netlog2014 07-14 t14-50-08-netlog
2014 07-14 t14-50-08-netlogBrandon Huynnh
 
Lec 6(Application Layer)
Lec 6(Application Layer)Lec 6(Application Layer)
Lec 6(Application Layer)
maamir farooq
 
Ftp server configuration on cisco packet tracer
Ftp server configuration on cisco packet tracerFtp server configuration on cisco packet tracer
Ftp server configuration on cisco packet tracer
prodhan999
 
Static NAT
Static NATStatic NAT
Static NAT
NetProtocol Xpert
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sk
sureshkarthick37
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the Web
Trevor Lohrbeer
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket TutorialGuo Albert
 
Wireshark Lab HTTP, DNS and ARP v7 solution
Wireshark Lab HTTP, DNS and ARP v7 solutionWireshark Lab HTTP, DNS and ARP v7 solution
Wireshark Lab HTTP, DNS and ARP v7 solution
United International University
 
DHCP & DNS
DHCP & DNSDHCP & DNS
DHCP & DNS
NetProtocol Xpert
 
Basics about IP address, DNS and DHCP.
Basics about IP address, DNS and DHCP.Basics about IP address, DNS and DHCP.
Basics about IP address, DNS and DHCP.
abhishek bhandare
 
Wireshark lab ssl v7 solution
Wireshark lab ssl v7 solutionWireshark lab ssl v7 solution
Wireshark lab ssl v7 solution
United International University
 

What's hot (20)

Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
 
Simple chat room using python
Simple chat room using pythonSimple chat room using python
Simple chat room using python
 
Python Sockets
Python SocketsPython Sockets
Python Sockets
 
Web tcp ip
Web tcp ipWeb tcp ip
Web tcp ip
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
 
retrieving the mail
retrieving the mailretrieving the mail
retrieving the mail
 
2014 07-14 t14-50-08-netlog
2014 07-14 t14-50-08-netlog2014 07-14 t14-50-08-netlog
2014 07-14 t14-50-08-netlog
 
Lec 6(Application Layer)
Lec 6(Application Layer)Lec 6(Application Layer)
Lec 6(Application Layer)
 
Ftp server configuration on cisco packet tracer
Ftp server configuration on cisco packet tracerFtp server configuration on cisco packet tracer
Ftp server configuration on cisco packet tracer
 
Static NAT
Static NATStatic NAT
Static NAT
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sk
 
Assigning ip addresses
Assigning ip addressesAssigning ip addresses
Assigning ip addresses
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the Web
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket Tutorial
 
Wireshark Lab HTTP, DNS and ARP v7 solution
Wireshark Lab HTTP, DNS and ARP v7 solutionWireshark Lab HTTP, DNS and ARP v7 solution
Wireshark Lab HTTP, DNS and ARP v7 solution
 
DHCP & DNS
DHCP & DNSDHCP & DNS
DHCP & DNS
 
Basics about IP address, DNS and DHCP.
Basics about IP address, DNS and DHCP.Basics about IP address, DNS and DHCP.
Basics about IP address, DNS and DHCP.
 
Wireshark lab ssl v7 solution
Wireshark lab ssl v7 solutionWireshark lab ssl v7 solution
Wireshark lab ssl v7 solution
 

Similar to Networking in Java

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
A.java
A.javaA.java
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Lan chat system
Lan chat systemLan chat system
Lan chat system
Wipro
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket ProgrammingMousmi Pawar
 
Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in java
Amol Gaikwad
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
EliasPetros
 
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
RashidFaridChishti
 
Java 1
Java 1Java 1
Networking.pptx
Networking.pptxNetworking.pptx
Networking.pptx
Esubesisay
 
Design an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing SoftwareDesign an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing Software
nilabarai
 
Socket programming
Socket programming Socket programming
Socket programming
Rajivarnan (Rajiv)
 
Socket
SocketSocket
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
Tushar B Kute
 

Similar to Networking in Java (20)

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
A.java
A.javaA.java
A.java
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Lan chat system
Lan chat systemLan chat system
Lan chat system
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 
Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in java
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 
Sockets
SocketsSockets
Sockets
 
28 networking
28  networking28  networking
28 networking
 
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
 
Java 1
Java 1Java 1
Java 1
 
Networking.pptx
Networking.pptxNetworking.pptx
Networking.pptx
 
Design an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing SoftwareDesign an Implementation of A Messaging and Resource Sharing Software
Design an Implementation of A Messaging and Resource Sharing Software
 
Socket programming
Socket programming Socket programming
Socket programming
 
Socket
SocketSocket
Socket
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Networking
NetworkingNetworking
Networking
 

Recently uploaded

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 

Networking in Java

  • 1. By – Gaurav GOFORELEARNING@GMAIL.COM Go GrEEN ! SaveEnvironment!
  • 2. There are 3 requirements to establish a network:  Hardware: includes the computers, cables, modems, hubs, etc  Software: includes program to communicate between server and clients  Protocols: represent a way to establish connection and helps in sending and receiving data in a standard format. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 3.  TCP/IP is a standard protocol model used on any network.  TCP/IP model has got the following 5 layers: 1. Application layer 2. TCP 3. IP 4. Data link layer 5. Physical layer By – Gaurav GOFORELEARNING@GMAIL.COM
  • 4. 1. Application layer ◦ Application layer is the topmost layer. ◦ This layer receives data from the application and formats the data. ◦ it sends that data to the next layer called TCP in the form of continuous stream of bytes. 2. TCP ◦ Receives data from Application layer, ◦ TCP will divide it into small segments called ‘packets’. A packet contains a group of bytes of data. ◦ These packets are then sent to next IP layer By – Gaurav GOFORELEARNING@GMAIL.COM
  • 5. 3. IP layer ◦ IP layer inserts the packets into envelopes called ‘frames’. ◦ Each frame contains a packet:  IP address of destination computer,  IP address of source computer,  some additional bits useful in error detection and correction. ◦ These frames are then sent to Data link layer By – Gaurav GOFORELEARNING@GMAIL.COM
  • 6. 4. Data Link Layer ◦ Receives frames from the IP Layer. ◦ Dispatches them to correct destination computer on the network. 5. Physical Layer ◦ This layer is used to physically transmit data on the network using the appropriate hardware. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 7.  TCP/IP takes care of number of bits sent and weather all the bits are received duly by the destination computer. so it is called ‘connection oriented reliable protocol’.  This protocol is highly suitable for transporting data reliably on a network.  Almost all the protocol on Internet uses TCP/IP model internally. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 8. IP Address:  An IP address is a Unique Identification number given to every computer on the network.  It contain four integer numbers in the range of 0 to 255 and separated by a dot as 209.191.88.254 DNS (domain naming service)  DNS is the mapping of IP addresses to human readable names. FTP (file transfer protocol)  Useful to download or upload files from and to the server. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 9. HTTP(Hypertext transfer protocol)  Most widely used protocol on Internet, which is used to transfer web pages (.html) from one computer to anoher computer on Internet. SMTP (simple mail transfer protocol)  Useful to send mails on network. POP(post office protocol)  Useful to receive mails into the mailboxes. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 10.  Protocol that transfer data in a connection less and unreliable manner.  It will not check how many bits are sent or received at the other side during transmission of data.  UDP is used to send images, audio files and video files.
  • 11.  Sockets provide the communication mechanism between two computers using TCP.  A client program creates a socket on its end of the communication and attempts to connect that socket to a server.  When the connection is made, the server creates a socket object on its end of the communication. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 12.  The client in socket programming must know two information: ◦ IP Address of Server, and ◦ Port number.  We should use a new port number for each new socket.  A socket, at server side is called ‘server socket’ and is created using ServerSocket class in Java.  A socket, at client side is called ‘socket’ and is created using Socket class in Java. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 13.  getByName() method of InetAddress class of java.net package. By – Gaurav GOFORELEARNING@GMAIL.COM getByName() Host Name / Server Name InetAddress/ IP Address
  • 14.  URL URL(Uniform Resource Locator) represents the address that is specified to access some information or resources on world wide web.  http://www.goforelearning.com:80/index.html  The URL contains 4 parts ◦ The protocol to use (http://). ◦ The server name or IP address of the server(www.goforelearning.com) ◦ The third part represents ports number, which is optional (:80) ◦ The last part is the file name or directory name that is referred (index.html).  URL is represented by a class ‘URL’ in java.net package. URL obj = new URL(String protocol, String host, int port, String path); By – Gaurav GOFORELEARNING@GMAIL.COM
  • 15. URLConnection Class is useful to actually connect to a website or resource on a network and get all the details of the website. For example,  To know the details of www.yahoo.com ◦ We should pass the URL to the object of URL class. ◦ Then using openConnection() method, we should establish a contact with the site on Internet. ◦ This method return URLConnection object. ◦ Then using URLConnection class method, we can display all the details of the website and also content of the webpage whose name is given in URL. By – Gaurav GOFORELEARNING@GMAIL.COM
  • 16. By – Gaurav GOFORELEARNING@GMAIL.COM Server Server Socket OutputStreamPrintStream ServerSocket ss = new ServerSocket (8080); Socket s = ss.accept(); OutputStream obj = s.getOutputStream(); PrintStream ps = new PrintStream (obj); ps.println(str); ss.close(); s.close() ps.close
  • 17. By – Gaurav GOFORELEARNING@GMAIL.COM Socket BufferedReaderInputStream Socket s = new Socket (“IPAddress” , port number) ; InputStream obj = s.get InputStream(); BufferedReader br = new BufferedReader (new InputStreamReader(obj)); Str = br.readLine(); br.close(); s.close() Client In case you don’t have your computer in a network, you have to run both the server and client programs in the same system. In that case, you can use localhost in place of IPAddress. The work localhost represents that the server is also locally available in the same system.
  • 18. We need additional streams both at server and client.  InputStream obj = s.getInputStream();  BufferedReader br = new BufferedReader (new InputStreamReader(obj));  OutputStream obj = s. getOutputStream();  DataOutputStream dos = new DataOutputStream(obj); writeBytes() method of DataOutputStream can be used to send strings in form of groups of bytes.
  • 19. Thank You ! Go GrEEN ! Save Environment! For Any Queries: GOFORELEARNING@GMAIL.COM