|
Introduction to networking
A
network is a set of computer and peripherals, which
are physically connected together. Networking
enables sharing resources and communication. Networking
in java
is possible through the use of java.net package. The
classes within this package encapsulate the socket
model
developed
by Berkeley software
division. The various terms are used in networking
they are
Protocol
Communication
between computer in network
or a different network requires certain set of rules
called protocols.
Socket
Socket
can be understood as a place used to plug in just
like electric sockets.
Client/Server
A
computer, which requests for some service from another
computer is called client. The one that processes
the request is called as server.
Internet address
Every
computer connected to a network
has a unique IP address. An IP address is a 32 bit
number which has four number separated by periods.
It is possible to connect to the Internet either directly
or by using Internet service provider.
Domain naming service
It
is very difficult to remember a set of number to connect
to the Internet. The domain naming service is used
to overcome this problem. It maps one particular IP
address to a string of characters.
InetAddress
There
are classes provided in java to enable networking.
They are found in the java.net package. InetAddress
is one such class, which is used to encapsulate the
IP address and the DSN. To create an instance of InetAddress
class factory method are used, as there are no visible
constructors available for this class. Factory methods
are conventions where static methods return an instance
of that class.
Datagram
Datagram
is type of packet that represents an entire communication.
There is no necessity to have connection or disconnection
stages when communicating using Datagram. There are
two classes in java, which enables communication-using
Datagram.
- Datagram packet is
the class, which acts as the data container
- Datagram socket is
a mechanism used to send or receive Datagram packets.
TCP/IP
TCP/IP
sockets are the most reliable, bi-directional, stream
protocols. It is possible to send arbitrary amount
of data using TCP/IP. Sockets are used for data communication
using this protocol. There are two kinds of sockets
in java – a server and client.
- A socket class object
establishes connection between the client and the
server.
- The server socket class object waits for the client
to make a connection.
|