Network Programming
The term network programming refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network. Such programs enable processes to communicate with each other across a network. Communication over a network takes place through protocols like Internet Protocol (IP), Transmission Control Protocol (TCP), User Datagram Protocol (UDP), etc.
Such protocols specify the format of data being sent over a network, along with how and when it is sent. At the other end of the communication, these protocols also define how the data is received along with its structure and what it means.
A key component of communication over the Internet is the address. An internet address or IP address is a 32 bit (IPv4, 128 bit in IPv6) number that uniquely identifies each computer physically attached to the Internet. This name can be associated with a domain name. An internet domain name is mapped to an IP address by the Domain Naming Service (DNS).
Very generally, most of the communications can be divided into connection-oriented, and connectionless. Whether the communication is connection-oriented, or connectionless, is defined by the communication protocol, and not by the application programming interface.
Examples of connection oriented protocols include TCP and Sequenced Packet Exchange (SPX), and Examples of connectionless protocols include User Datagram Protocol (UDP), “raw IP“, and Internetwork Packet Exchange (IPX).
For connection-oriented communications, communication parties usually have different roles. One party is usually waiting for incoming connections; this party is usually referred to as the server. Another party is the one that initiates connection; this party is usually referred to as the client.
For connectionless communications, one party (server) is usually waiting for an incoming packet, and another party (client) is usually understood as the one which sends an unsolicited packet to the server.
TCP is typically used over the Internet Protocol, which is referred to as TCP/IP. It provides a serialized, predictable, and reliable stream of packet data. However, TCP includes many complex algorithms for dealing with congestion control on crowded networks.
UDP, an alternative to TCP, supports fast and connection-less transport of packets. Though they are unreliable as there is no assurance that the packet is not damaged in transit or that whoever sent it is still there to receive a response. UDP relies on a few network resources. TCP is useful for implementing network services — such as remote login (login, telnet) and file transfer (FTP) — which require data of indefinite length to be transferred. UDP is less complex and incurs fewer overheads. It is often used in implementing client/server applications in distributed systems built over local area networks.
Conclusion
Network programs enable processes to communicate with each other across a network. The java.net
the package provides a powerful and flexible infrastructure for network programming.