SlideShare une entreprise Scribd logo
1  sur  15
Internet Address
Devices connected to the Internet are called nodes. Nodes that are
computers are called hosts. Each node or host is identified by at least one
unique 32-bit number called an Internet address, an IP address, or a host
address, depending on who you talk to. This takes up exactly four bytes of
memory.
An IP address is normally written as four unsigned bytes, each ranging
from to 255, with the most significant byte first. Bytes are separated by
periods for the convenience of human eyes. For example, the address for
hermes.oit.unc.edu is 152.2.21.1. This is called the dotted quad format.
IP addresses are great for computers, but they are a problem for humans,
who have a hard time remembering long numbers. In the 1950s, it was
discovered that most people could remember about seven digits per
number; some can remember as many as nine, while others remember
as few as five.
This is why phone numbers are broken into three- and four-digit pieces
with three-digit area codes. Obviously an IP address, which can have as
many as 12 decimal digits, is beyond the capacity of most humans to
remember.
Domain Name System (DNS)
To avoid the need to carry around Rolodexes full of IP addresses, the
designers of the Internet invented the Domain Name System (DNS).
DNS associates hostnames that humans can remember (like
hermes.oit.unc.edu) with IP addresses that computers can remember
(such as 152.2.21.1).[2] Most hosts have at least one hostname. An
exception is made for computers that don't have a permanent IP
address (like many PCs); since these computers don't have a
permanent address, they can't be used as servers and therefore don't
need a name, since nobody will need to refer to them.
Every computer connected to the Internet should have access to a
machine called a domain name server.
Unix box running special DNS software that knows the mappings
between different hostnames and IP addresses.
InetAddress Class
The java.net.InetAddress class is Java's encapsulation of an IP address.
It is used by most of the other networking classes, including Socket,
ServerSocket, URL, DatagramSocket, DatagramPacket, and more.
public final class InetAddress extends Object implements Serializable
There are no public constructors in the InetAddress class. However,
InetAddress has three static methods that return suitably initialized
InetAddress objects, given a little information. They are:
public static InetAddress InetAddress.getByName(String hostName)
throws UnknownHostException
public static InetAddress[] InetAddress.getAllByName(String
hostName)
throws UnknownHostException
public static InetAddress InetAddress.getLocalHost( )
throws UnknownHostException
import java.net.*;
public class OReillyByAddress {
public static void main (String[] args)
{
try {
InetAddress address =
InetAddress.getByName("204.148.40
.9");
System.out.println (address);
}
catch (UnknownHostException e) {
System.out.println ("Could not find
204.148.40.9");
}
}
}
% java OReillyByAddress
helio.ora.com/204.148.40.9
import java.net.*;
public class OReillyByName {
public static void main (String[]
args) {
try {
InetAddress address =
InetAddress.getByName("www.ore
illy.com");
System.out.println(address);
}
catch (UnknownHostException e) {
System.out.println("Could not find
www.oreilly.com");
}
}
}
% java OReillyByName
www.oreilly.com/204.148.40.9
Find the address of the local machine
Activity
import java.net.*;
public class MyAddress {
public static void main (String[] args) {
try {
InetAddress address =
InetAddress.getLocalHost( );
System.out.println(address);
}
catch (UnknownHostException e) {
System.out.println("Could not find this
computer's address.");
}
}
}
Socket programming
Sockets for Clients
A socket is a connection between two hosts.
Operations
The program creates a new socket with a Socket ( )
constructor.
The socket attempts to connect to the remote host.
Once the connection is established, the local and remote
hosts get input and output streams from the socket and use
those streams to send data to each other. This connection is
full-duplex; both hosts can send and receive data
simultaneously.
When the transmission of data is complete, one or both
sides close the connection.
Constructors
1. public Socket (String host, int port) throws
UnknownHostException, IOException
This constructor creates a TCP socket to the specified port
on the specified host and attempts to connect to the
remote host.
2. public Socket(InetAddress host, int port) throws
IOException
This constructor creates a TCP socket to the specified port
on the specified host and tries to connect. It differs by
using an InetAddress object to specify the host rather than
a hostname.
Write a program for
Find out which of the Ports at or Above 1,024
Seem to Be Hosting TCP Server
Datagram Packet
UDP datagram is represented by an instance of the DatagramPacket
class public final class DatagramPacket extends Object
Constructors
Receiving datagram
1. public DatagramPacket(byte[] buffer, int length)
When a socket receives a datagram, it stores the datagram's data part
in buffer beginning at buffer[0] and continuing until the packet is
completely stored or until length bytes have been written into the
buffer.
2. public DatagramPacket(byte[] buffer, int offset, int length)
When a socket receives a datagram, it stores the datagram's data part
in buffer beginning at buffer[offset] and continuing until the packet is
completely stored or until length bytes have been written into the
buffer.
Sending datagram
1. public DatagramPacket(byte[] data, int length, InetAddress
destination, int port)
2. public DatagramPacket(byte[] data, int offset, int length,
InetAddress destination, int port)
Each constructor creates a new DatagramPacket to be sent to
another host. The packet is filled with length bytes of the data array
starting at offset or if offset is not used. If you try to construct a
DatagramPacket with a length that is greater than data.length, the
constructor throws an IllegalArgumentException.
Example: 1
A java program establishes socket connection
between two hosts. The connection is
maintained through the mentioned port number
to implement client server communication.
E-mail Client
An email client, email reader, or more formally mail user agent
(MUA), is a computer program used to manage email.
The term email client may refer to any agent acting as a client
toward an email server, regardless of it being a mail user agent, a
relaying server, or a human typing on a terminal.
A web application providing message management, composition,
and reception functionality is sometimes considered an email
client.
Retrieving messages from a mailbox
Like most client programs, an MUA is only active when a user runs
it. Messages arrive on the Mail Transfer Agent (MTA) server.
Unless the MUA has access to the server's disk, messages are
stored on a remote server and the MUA has to request them on
behalf of the user.
In the first case, shared disk, a user logs on a server and runs an
MUA on that machine. The MUA reads messages from a
conventionally formatted storage, typically mbox, within the user's
HOME directory.
The MTA uses a suitable mail delivery agent (MDA) to add
messages to that storage, possibly in concurrence with the MUA.
This is the default setting on many UNIX systems. Web mail
applications running on the relevant server can also benefit from
direct disk access to the mail storage.
For personal computing, and whenever messages are stored on a
remote system, a mail user agent connects to a remote mailbox to
retrieve messages.
Formatting messages
Submitting messages to a server
Encryption
Encryption of mail sessions
Encryption of the message body
Standards
Port numbers
Activity
Web page retrieval
To locate and retrieve data from the network is to use
the URL class.
Write a program to Download a Web Page using java
import java.

Contenu connexe

Tendances

Networking
NetworkingNetworking
Networking
Tuan Ngo
 
The Internet and World Wide Web
The Internet and World Wide WebThe Internet and World Wide Web
The Internet and World Wide Web
webhostingguy
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
Pradeep Kumar TS
 

Tendances (20)

Socket
SocketSocket
Socket
 
Networking
NetworkingNetworking
Networking
 
Socket programming-in-python
Socket programming-in-pythonSocket programming-in-python
Socket programming-in-python
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
internet protocol
internet protocolinternet protocol
internet protocol
 
Unit-4 networking basics in java
Unit-4 networking basics in javaUnit-4 networking basics in java
Unit-4 networking basics in java
 
Multiplayer Java Game
Multiplayer Java GameMultiplayer Java Game
Multiplayer Java Game
 
Ipc
IpcIpc
Ipc
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 Th
 
The Internet and World Wide Web
The Internet and World Wide WebThe Internet and World Wide Web
The Internet and World Wide Web
 
Web design EJ3
Web design    EJ3Web design    EJ3
Web design EJ3
 
Python Sockets
Python SocketsPython Sockets
Python Sockets
 
vishal_sharma: python email sending software
vishal_sharma: python email sending software  vishal_sharma: python email sending software
vishal_sharma: python email sending software
 
Java
JavaJava
Java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Java 1
Java 1Java 1
Java 1
 
Python network programming
Python   network programmingPython   network programming
Python network programming
 
socket programming
socket programming socket programming
socket programming
 

En vedette (10)

Inet
InetInet
Inet
 
Hertz
HertzHertz
Hertz
 
2012 grand hyatt taipei presentation
2012 grand hyatt taipei presentation2012 grand hyatt taipei presentation
2012 grand hyatt taipei presentation
 
Hertz 租車
Hertz 租車Hertz 租車
Hertz 租車
 
達美航空
達美航空達美航空
達美航空
 
Premium outlets
Premium outletsPremium outlets
Premium outlets
 
美國阿拉斯加州
美國阿拉斯加州美國阿拉斯加州
美國阿拉斯加州
 
美國愛達荷州亞太區辦事處
美國愛達荷州亞太區辦事處美國愛達荷州亞太區辦事處
美國愛達荷州亞太區辦事處
 
2012.10.11 我的美國主題樂園之旅記者會
2012.10.11 我的美國主題樂園之旅記者會2012.10.11 我的美國主題樂園之旅記者會
2012.10.11 我的美國主題樂園之旅記者會
 
Java API: java.net.InetAddress
Java API: java.net.InetAddressJava API: java.net.InetAddress
Java API: java.net.InetAddress
 

Similaire à Session 6

Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
Kavita Sharma
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
Mousmi Pawar
 
Published on IST 554 (httpsonline.ist.psu.eduist554).docx
Published on IST 554 (httpsonline.ist.psu.eduist554).docxPublished on IST 554 (httpsonline.ist.psu.eduist554).docx
Published on IST 554 (httpsonline.ist.psu.eduist554).docx
amrit47
 
Pears
PearsPears
Pears
thips
 
Internetbasics
InternetbasicsInternetbasics
Internetbasics
patinijava
 

Similaire à Session 6 (20)

Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
28 networking
28  networking28  networking
28 networking
 
Internet, Intranet & Extranet & IP and MAC
Internet, Intranet & Extranet & IP and MACInternet, Intranet & Extranet & IP and MAC
Internet, Intranet & Extranet & IP and MAC
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 
maXbox Arduino Tutorial
maXbox Arduino TutorialmaXbox Arduino Tutorial
maXbox Arduino Tutorial
 
GSBA - IT Orientation Program by Prof. Amit Chandra
GSBA - IT Orientation Program by Prof. Amit ChandraGSBA - IT Orientation Program by Prof. Amit Chandra
GSBA - IT Orientation Program by Prof. Amit Chandra
 
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriyaIPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
 
How Internet Works
How Internet WorksHow Internet Works
How Internet Works
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
How does the internet work
How does the internet workHow does the internet work
How does the internet work
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Networking slide
Networking slideNetworking slide
Networking slide
 
Networking And Internet
Networking And InternetNetworking And Internet
Networking And Internet
 
Published on IST 554 (httpsonline.ist.psu.eduist554).docx
Published on IST 554 (httpsonline.ist.psu.eduist554).docxPublished on IST 554 (httpsonline.ist.psu.eduist554).docx
Published on IST 554 (httpsonline.ist.psu.eduist554).docx
 
Pears
PearsPears
Pears
 
Understanding computer networks
Understanding computer networksUnderstanding computer networks
Understanding computer networks
 
Application layer
Application layerApplication layer
Application layer
 
Internetbasics
InternetbasicsInternetbasics
Internetbasics
 

Plus de Parthipan Parthi (20)

Inheritance
Inheritance Inheritance
Inheritance
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
802.11 mac
802.11 mac802.11 mac
802.11 mac
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Computer network
Computer networkComputer network
Computer network
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Queuing analysis
Queuing analysisQueuing analysis
Queuing analysis
 
WAP
WAPWAP
WAP
 
Alternative metrics
Alternative metricsAlternative metrics
Alternative metrics
 
Ethernet
EthernetEthernet
Ethernet
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Data structures1
Data structures1Data structures1
Data structures1
 
Data structures 4
Data structures 4Data structures 4
Data structures 4
 
Data structures2
Data structures2Data structures2
Data structures2
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Io stream
Io streamIo stream
Io stream
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3 REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
 

Dernier

Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 

Dernier (20)

Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 

Session 6

  • 1. Internet Address Devices connected to the Internet are called nodes. Nodes that are computers are called hosts. Each node or host is identified by at least one unique 32-bit number called an Internet address, an IP address, or a host address, depending on who you talk to. This takes up exactly four bytes of memory. An IP address is normally written as four unsigned bytes, each ranging from to 255, with the most significant byte first. Bytes are separated by periods for the convenience of human eyes. For example, the address for hermes.oit.unc.edu is 152.2.21.1. This is called the dotted quad format. IP addresses are great for computers, but they are a problem for humans, who have a hard time remembering long numbers. In the 1950s, it was discovered that most people could remember about seven digits per number; some can remember as many as nine, while others remember as few as five. This is why phone numbers are broken into three- and four-digit pieces with three-digit area codes. Obviously an IP address, which can have as many as 12 decimal digits, is beyond the capacity of most humans to remember.
  • 2. Domain Name System (DNS) To avoid the need to carry around Rolodexes full of IP addresses, the designers of the Internet invented the Domain Name System (DNS). DNS associates hostnames that humans can remember (like hermes.oit.unc.edu) with IP addresses that computers can remember (such as 152.2.21.1).[2] Most hosts have at least one hostname. An exception is made for computers that don't have a permanent IP address (like many PCs); since these computers don't have a permanent address, they can't be used as servers and therefore don't need a name, since nobody will need to refer to them. Every computer connected to the Internet should have access to a machine called a domain name server. Unix box running special DNS software that knows the mappings between different hostnames and IP addresses.
  • 3. InetAddress Class The java.net.InetAddress class is Java's encapsulation of an IP address. It is used by most of the other networking classes, including Socket, ServerSocket, URL, DatagramSocket, DatagramPacket, and more. public final class InetAddress extends Object implements Serializable There are no public constructors in the InetAddress class. However, InetAddress has three static methods that return suitably initialized InetAddress objects, given a little information. They are: public static InetAddress InetAddress.getByName(String hostName) throws UnknownHostException public static InetAddress[] InetAddress.getAllByName(String hostName) throws UnknownHostException public static InetAddress InetAddress.getLocalHost( ) throws UnknownHostException
  • 4. import java.net.*; public class OReillyByAddress { public static void main (String[] args) { try { InetAddress address = InetAddress.getByName("204.148.40 .9"); System.out.println (address); } catch (UnknownHostException e) { System.out.println ("Could not find 204.148.40.9"); } } } % java OReillyByAddress helio.ora.com/204.148.40.9 import java.net.*; public class OReillyByName { public static void main (String[] args) { try { InetAddress address = InetAddress.getByName("www.ore illy.com"); System.out.println(address); } catch (UnknownHostException e) { System.out.println("Could not find www.oreilly.com"); } } } % java OReillyByName www.oreilly.com/204.148.40.9
  • 5. Find the address of the local machine Activity import java.net.*; public class MyAddress { public static void main (String[] args) { try { InetAddress address = InetAddress.getLocalHost( ); System.out.println(address); } catch (UnknownHostException e) { System.out.println("Could not find this computer's address."); } } }
  • 6. Socket programming Sockets for Clients A socket is a connection between two hosts. Operations The program creates a new socket with a Socket ( ) constructor. The socket attempts to connect to the remote host. Once the connection is established, the local and remote hosts get input and output streams from the socket and use those streams to send data to each other. This connection is full-duplex; both hosts can send and receive data simultaneously. When the transmission of data is complete, one or both sides close the connection.
  • 7. Constructors 1. public Socket (String host, int port) throws UnknownHostException, IOException This constructor creates a TCP socket to the specified port on the specified host and attempts to connect to the remote host. 2. public Socket(InetAddress host, int port) throws IOException This constructor creates a TCP socket to the specified port on the specified host and tries to connect. It differs by using an InetAddress object to specify the host rather than a hostname.
  • 8. Write a program for Find out which of the Ports at or Above 1,024 Seem to Be Hosting TCP Server
  • 9. Datagram Packet UDP datagram is represented by an instance of the DatagramPacket class public final class DatagramPacket extends Object Constructors Receiving datagram 1. public DatagramPacket(byte[] buffer, int length) When a socket receives a datagram, it stores the datagram's data part in buffer beginning at buffer[0] and continuing until the packet is completely stored or until length bytes have been written into the buffer. 2. public DatagramPacket(byte[] buffer, int offset, int length) When a socket receives a datagram, it stores the datagram's data part in buffer beginning at buffer[offset] and continuing until the packet is completely stored or until length bytes have been written into the buffer.
  • 10. Sending datagram 1. public DatagramPacket(byte[] data, int length, InetAddress destination, int port) 2. public DatagramPacket(byte[] data, int offset, int length, InetAddress destination, int port) Each constructor creates a new DatagramPacket to be sent to another host. The packet is filled with length bytes of the data array starting at offset or if offset is not used. If you try to construct a DatagramPacket with a length that is greater than data.length, the constructor throws an IllegalArgumentException.
  • 11. Example: 1 A java program establishes socket connection between two hosts. The connection is maintained through the mentioned port number to implement client server communication.
  • 12. E-mail Client An email client, email reader, or more formally mail user agent (MUA), is a computer program used to manage email. The term email client may refer to any agent acting as a client toward an email server, regardless of it being a mail user agent, a relaying server, or a human typing on a terminal. A web application providing message management, composition, and reception functionality is sometimes considered an email client.
  • 13. Retrieving messages from a mailbox Like most client programs, an MUA is only active when a user runs it. Messages arrive on the Mail Transfer Agent (MTA) server. Unless the MUA has access to the server's disk, messages are stored on a remote server and the MUA has to request them on behalf of the user. In the first case, shared disk, a user logs on a server and runs an MUA on that machine. The MUA reads messages from a conventionally formatted storage, typically mbox, within the user's HOME directory. The MTA uses a suitable mail delivery agent (MDA) to add messages to that storage, possibly in concurrence with the MUA. This is the default setting on many UNIX systems. Web mail applications running on the relevant server can also benefit from direct disk access to the mail storage. For personal computing, and whenever messages are stored on a remote system, a mail user agent connects to a remote mailbox to retrieve messages.
  • 14. Formatting messages Submitting messages to a server Encryption Encryption of mail sessions Encryption of the message body Standards Port numbers
  • 15. Activity Web page retrieval To locate and retrieve data from the network is to use the URL class. Write a program to Download a Web Page using java import java.