Note: Lecture 8 Java network programming

Think before class 1 What is TCP / IP protocol?   2. What are the two transmission protocols of TCP / IP and what are their characteristics?   3. What is a URL?   4. What is the relationship between URL and IP address?   5. What is socket? 6. The relationship between socket and TCP / IP protocol? 7. The relationship between URL and socket? 8.1 basic concept of network programming and introduction to TCP / IP protocol

The purpose of network programming is to communicate with other computers directly or indirectly through network protocol. There are two main problems in network programming. One is how to accurately locate one or more hosts on the network, and the other is how to reliably and efficiently transmit data after finding the hosts. In TCP / IP protocol, IP layer is mainly responsible for the positioning of network hosts and the routing of data transmission. A host on the Internet can be uniquely determined by IP address. TCP layer provides application-oriented reliable or unreliable data transmission mechanism, which is the main object of network programming. Generally, it does not need to care about how IP layer processes data. At present, the more popular network programming model is client / server (C / s) structure. That is, one of the communication parties acts as a server to wait for and respond to the customer's request. The customer applies to the server when the service is needed. The server generally runs as a daemon and listens to the network port. Once there is a customer's request, it will start a service process to respond to the customer. At the same time, it will continue to listen to the service port to make subsequent customers Households can also get services in time.

8.1. 3. Two types of transmission protocols: TCP; UDP although TCP is the only protocol name in the TCP / IP protocol name, there are both TCP and UDP protocols in the TCP / IP transport layer.

TCP is the abbreviation of tranfer control protocol. It is a connection oriented protocol to ensure reliable transmission. Through TCP protocol transmission, we get a sequential error free data stream. A connection must be established between the two paired sockets of the sender and the receiver in order to communicate on the basis of TCP protocol, When a socket (usually server socket) when waiting to establish a connection, the other socket can request a connection. Once the two sockets are connected, they can carry out two-way data transmission, and both sides can send or receive. UDP is the abbreviation of user datagram protocol. It is a connectionless protocol. Each datagram is an independent information, including The complete source address or destination address is transmitted to the destination by any possible path on the network. Therefore, whether it can reach the destination, the time of reaching the destination and the correctness of the content can not be guaranteed. Let's make a simple comparison between the two protocols: when using UDP, each datagram gives complete address information, so there is no need to establish a connection between the sender and the receiver. For TCP protocol, because it is a connection oriented protocol, a connection must be established before data transmission between sockets, so there is an additional time for connection establishment in TCP. There is a size limit when using UDP to transmit data. Each transmitted datagram must be limited to 64KB. TCP has no such limitation. Once the connection is established, the sockets of both sides can transmit a large amount of data in a unified format. UDP is an unreliable protocol. The datagrams sent by the sender do not necessarily arrive at the receiver in the same order. TCP is a reliable protocol, which ensures that the receiver completely and correctly obtains all the data sent by the sender. In short, TCP has strong vitality in network communication, For example, remote connection (telnet) and file transfer (FTP) requires data of variable length to be reliably transmitted. In contrast, UDP is simple to operate and requires less monitoring. Therefore, it is usually used for client / server applications in decentralized systems with high reliability of LAN. Readers may ask, since there is a TCP protocol to ensure reliable transmission, why do you want a non Reliable UDP protocol? The main reasons are: Two. First, reliable transmission comes at a price. The verification of the correctness of data content will inevitably occupy the processing time of the computer and the bandwidth of the network. Therefore, the efficiency of TCP transmission is not as high as UDP. Second, strict transmission reliability does not need to be guaranteed in many applications, such as video conference system, which does not require the absolute correctness of audio and video data, as long as consistency is guaranteed. In this case, it is obviously more reasonable to use UDP.

8.2 URL based high-level Java network programming

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>