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
Socket can be understood as a place used to plug in just like electric sockets.
A computer, which requests for some service from another computer is called client. The one that processes the request is called as server.
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.
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 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.
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.