The 19th chapter of network communication----Network Programming Foundation

Source: Internet
Author: User

  Network programming refers to writing programs that communicate with other computers. Java has encapsulated the things that a network program needs into different classes. Whenever you create objects of these classes, use the appropriate method.

1. LAN and Internet

To enable communication between two computers, you must connect two computers with one network line.

A server is a computer or program that provides information, a client is a computer or program that requests information, and a network is used to connect a server to a client to communicate with each other. But sometimes it is difficult to separate the server from the client area in a network.

The local area network (Network,lan), which we usually call, is a group of computers connected by certain forms. It can be composed of two computers or thousands of computers in the same region. Extended from a LAN to a larger range, such a network is called a WAN (Wide area Network,wan). The internet we are familiar with is made up of countless LANs and WANs.

2. Network protocol

  The network protocol specifies the physical and mechanical connection between the computer (network cable and network card), the electrical (effective level range) and other characteristics and the inter-computer addressing rules, data transmission conflict resolution, how long data is segmented and received. It's like there are different laws in different countries.

(1) IP protocol

IP is the abbreviation of Internet Protocol, it is a kind of network protocol. The protocol used by the Internet network is the TCP/IP protocol. The Internet relies on TCP/IP protocol to realize the interconnection of different hardware structures, different operating systems and different network systems on a global scale.

  hundreds of billions of hosts exist on the Internet network, and each host represents itself on the network with its assigned Internet address, which is an IP address . So far the IP address is represented by a 4-byte, 32-bit binary number called IPV4. For ease of use, the decimal number of each byte is usually taken, and each byte is separated by dots to represent the IP address, such as: 192.168.1.1. Now people are experimenting with 16 bytes to represent an IP address, which is IPv6. TCP/IP mode is a hierarchical structure that is divided into 4 tiers.

(2) TCP and UDP

The TCP protocol is a fixed-line-based protocol that provides reliable data transfer between two computers. TCP guarantees that the data can be delivered to the other end of the connection from one end of the data, and that the data arrives in the same order as it was sent out, so the TCP protocol is suitable for high reliability requirements.

UDP is a non-connected communication protocol that does not guarantee the transmission of reliable data, but can send data to several targets and receive data from several sources. UDP is done in a way that sends packets independently. This way, like a postman delivering letters to the addressee, can base many letters on the same person, and each letter is relatively independent, the order in which the letters are delivered is not important, and the order in which the recipients receive the letters is not guaranteed to be the same as the order of the underlying letters. UDP protocol is suitable for some occasions where the accuracy of data is not high, such as network chat room, online movie, etc.

The TCP protocol has an additional cost of authentication, which may slow down the transmission, while the UDP protocol may be more appropriate for these sites with very fast transmission speeds and aging requirements.

3. Ports and sockets

In general, a computer only has a single physical connection to the network, all the data through this connection to the internal and external to the specific computer, this is the port. The port in network programming is not a real physical existence, but an imaginary connection device.

The port is defined as an integer between 0~65536. HTTP services typically use port 80, and the FTP service uses 21 ports. If a computer provides a variety of services such as HTTP, FTP, and so on, the client is given the opportunity to determine which service is connected to the server by the port. Typically, the number of ports between 0~1023 is used for some well-known network services and applications, and the user's normal network application should use more than 1024 of the port number to avoid the port number conflicts with another application or system service.

  a socket (socket) in a network program is used to connect an application to a port. sockets are an imaginary connection device, like a plug-in device "receptacle" for connecting electrical appliances to wires.

The 19th chapter of network communication----Network Programming Foundation

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.