The term network programming refers to the writing of programmes running through several devices ( computers), all of which use a network to link the devices to each other.
The java.net J2SE APIs package includes a set of classes and interfaces that include descriptions of low-level communication , allowing you to write programmes that concentrate on solving the issue at hand.
For the two generic network protocols, the java.net package provides support
TCP stands for Transmission Control Protocol, which enables two applications to communicate efficiently. Over the Internet Protocol, which is referred to as TCP / IP, TCP is usually used.
UDP stands for User Datagram Protocol, a connection-less protocol that allows data packets between applications to be transmitted.
This segment offers a clear understanding of the two topics below.
1. Socket Programming:
This is the most frequently used networking concept and has been discussed in great detail.
The communication mechanism between two computers using TCP is provided by sockets. At the end of the communication, a client programme creates a socket and attempts to connect the socket to a server.
When the connexion is made, a socket object at the end of the communication is generated by the server. By writing to and reading from the socket, the client and the server will now interact.
Socket class Methods:
1. public Socket(String host, int port) throws UnknownHostException, IOException.
This method attempts to connect to the specified server at the specified port. If this constructor does not throw an exception, the connection is successful and the client is connected to the server.
2. public Socket(InetAddress host, int port) throws IOException
This method is identical to the previous constructor, except that the host is denoted by an InetAddress object.
3. public Socket(String host, int port, InetAddress localAddress, int localPort) throws IOException.
Connects to the specified host and port, creating a socket on the local host at the specified address and port.
4. public Socket(InetAddress host, int port, InetAddress localAddress, int localPort) throws IOException.
This method is identical to the previous constructor, except that the host is denoted by an InetAddress object instead of a String.
5. public Socket()
Creates an unconnected socket. Use the connect() method to connect this socket to a server.