Networking PDF
Networking PDF
Networking PDF
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 1|Page
JAVA Means DURGASOFT
networking
Introduction to networking:-
1) The process of connecting the resources (computers) together to share the data is called
networking.
2) Java.net is package it contains number of classes by using that classes we are able to
connection between the devices (computers) to share the information.
3) Java.net package provide support for the TCP (Transmission Control Protocol),UDP(user data
gram protocol) protocols.
Categories of network:-
We are having two types of networks
1) Per-to-peer network.
2) Client-server network.
Client-server:-
In the client server architecture always client system behaves as a client and server system
behaves as a server.
Peer-to-peer:-
Inthe peer to peer client system sometimes behaves as a server, server system sometimes
behaves like a client the roles are not fixed.
Types of networks:-
Intranet:-
It is also known as a private network. To share the information in limited area
range(within the organization) then we should go for intranet.
Internet:-
It is also known as public networks. Where the data maintained in a centralized server
hence we are having more sharability. And we can access the data from anywhere else.
Extranet:-
This is extension to the private network means other than the organization , authorized
persons able to access.
The frequently used terms in the networking:-
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 2|Page
JAVA Means DURGASOFT
1) IP Address
2) URL(Uniform Resource Locator)
3) Protocol
4) Port Number
5) MAC address.
6) Connection oriented and connection less protocol
7) Socket.
Protocol:-
Protocol is a set of rules fallowed by the every computer present in the network this is useful to
send the data physically from one place to another place in the network.
TCP(Transmission Control Protocol)(connection oriented protocol)
UDP (User Data Gram Protocol)(connection less protocol)
Telnet
SMTP(Simple Mail Transfer Protocol)
IP (Internet Protocol)
IP Address:-
1) IP Address is a unique identification number given to the computer to indentify it uniquely
in the network.
2) The IP Address is uniquely assigned to the computer it is not duplicated.
3) The IP Address range is 0-255 if we are giving the other than this range that is not allowed.
4) We can identify the particular computer in the network with the help of IP Address.
5) The IP Address contains four digit number
a. 125.0.4.255----good
b. 124.654.5.6-----bad
c. 1.2.3.4.5.6-------bad
6) Each and every website contains its own IP Address we can access the sites through the
names otherwise IP Address.
Site Name :- www.google.com
IP Address :- 74.125.224.72
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 3|Page
JAVA Means DURGASOFT
Ex:-
import java.net.*;
import java.io.*;
class Test
{
public static void main(String[] args) throws Exception
{
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
System.out.println("please enter site name");
String sitename=br.readLine();
InetAddress in=InetAddress.getByName(sitename);
System.out.println("the ip address is:"+in);
}
}
java Test
www.yahoo.com
The IP Address is: www.yahoo.com/ 106.10.139.246
Java Test
Please press enter key then we will get IP Address of the system.
The IP Address is : local host/we are getting IP Address of the system
Note:-
If the internet is not available we are getting java.net.UnKnownHostException.
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 4|Page
JAVA Means DURGASOFT
http://www.Sravyasoft.com:10/Corejava_rattaiah.asp
To achieve the fallowing communication the java peoples are provided the fallowing classes.
a. Socket
b. ServerSocket
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 5|Page
JAVA Means DURGASOFT
Application Layer
TCP
IP
Physical Layer
Application Layer:-
Takes the data from the application and sends it to the TCP layer.
TCP Protocol:-
it will take the data which is coming from Application Layer and divides in to small units called
Packets. Then transfer those packets to the next layer called IP. The packet contains group of
bytes of data.
IP:-
It will take the packets which is coming from TCP and prepare envelop called ‘frames’ hence the
frame contains the group of packets. Then it will identify the particular target machine on the
basis of the IP address and sent that frames to the physical layer.
Physical Layer:-
Based on the physical medium it will transfer the data to the target machine.
To achieve the UDP communication the java peoples are provided the fallowing classes.
1. DataGrampacket.
2. DataGramSocket.
Socket:-
1) Socket is used to create the connection between the client and server.
2) Socket is nothing but a combination of IP Address and port number.
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 6|Page
JAVA Means DURGASOFT
Client.java:-
import java.net.*;
import java.io.*;
class Client
{
public static void main(String[] args)throws Exception
{
Socket s=new Socket("localhost",5555);
String str="ratan from client";
OutputStreamos=s.getOutputStream();
PrintStreamps=new PrintStream(os);
ps.println(str);
InputStream is=s.getInputStream();
BufferedReaderbr=new BufferedReader(new InputStreamReader(is));
String str1=br.readLine();
System.out.println(str1);
}
}
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 7|Page
JAVA Means DURGASOFT
Server.java:-
import java.io.*;
import java.net.*;
class Server
{
public static void main(String[] args) throws Exception
{
//to read the data from client
ServerSocketss=new ServerSocket(5555);
Socket s=ss.accept();
OutputStreamos=s.getOutputStream();
PrintStreamps=new PrintStream(os);
ps.println(data);
}
}
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 8|Page
JAVA Means DURGASOFT
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 9|Page
JAVA Means DURGASOFT
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com 10 | P a g e