Basic concepts of JAVA Network Programming

Source: Internet
Author: User

Network programming aims to communicate directly or indirectly with other computers through network protocols. There are two main problems in network programming: How to accurately locate one or more hosts on the network, and how to transmit data reliably and efficiently after finding the hosts. In TCP/IP, the IP layer is mainly responsible for locating network hosts and routing data transmission. The IP address can uniquely identify a host on the Internet. The TCP layer provides a reliable or unreliable data transmission mechanism for applications, which is the main object of network programming. Generally, you do not need to care about how the IP layer processes data.
Currently, the popular network programming model is the Client/Server (C/S) structure. That is, one Party serves as the server to wait for the customer to make a request and respond. The customer applies to the server when the service is required. The server is always running as a daemon and listens to the network port. Once a customer requests the server, a service process is started to respond to the customer. At the same time, the server continues to listen to the Service port, this allows later customers to get services in a timely manner.

Two types of transmission protocols: TCP and UDP
Although the TCP/IP protocol name only has the TCP protocol name, both TCP and UDP protocols exist in the TCP/IP transport layer.

TCPIt is short for Tranfer Control Protocol. It is a connection-oriented Protocol that ensures reliable transmission. It is transmitted over TCP to obtain a sequential error-free data stream. The sender and receiver must establish a connection between two pairs of sockets to facilitate communication based on the TCP protocol. When a socket (usually a server socket) is waiting to establish a connection, another socket can require a connection. Once the two sockets are connected, they can perform bidirectional data transmission, and both parties can send or receive data.
  UDPIs the abbreviation of User datasync Protocol. It is a connectionless Protocol. Each Datagram is an independent information, including the complete source address or destination address, it is transmitted to the destination in any possible path on the network. Therefore, the correctness of the arrival time, arrival time, and content cannot be guaranteed.

Http://www.cnblogs.com/roucheng/
The following is a simple comparison of the two Protocols:
When UDP is used, the complete address information is provided in each datagram, so there is no need to establish a connection between the sender and the receiver. For TCP, because it is a connection-oriented protocol, a connection must be established before data transmission between sockets. Therefore, a connection is added in TCP.
When using UDP to transmit data, there is a size limit. Each transmitted datagram must be within 64 KB. TCP does not have such restrictions. Once the connection is established, the sockets of both parties can transmit a large amount of data in a unified format. UDP is an unreliable protocol. The data packets sent by the sender do not necessarily arrive at the receiver in the same order. TCP is a reliable protocol that ensures that the receiver fully and correctly obtains all data sent by the sender.
In short, TCP has a strong vitality in network communication. For example, remote connection (Telnet) and file transmission (FTP) both require indefinite data to be reliably transmitted. In contrast, UDP is easy to operate and requires less monitoring. Therefore, it is usually used for client/server applications in distributed systems with high LAN reliability.
Readers may ask, since there is a TCP protocol that ensures reliable transmission, why do we need a non-reliable UDP protocol? There are two main reasons. First, reliable transmission requires a price. The test of the correctness of data content will inevitably take up the processing time and bandwidth of the computer. Therefore, TCP transmission is not as efficient as UDP. Second, in many applications, strict transmission reliability is not required. For example, video conferencing systems do not require absolute correctness of audio and video data, as long as consistency is ensured, in this case, it is more reasonable to use UDP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.